Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,16 @@ module Crystal
assert_syntax_error "def foo=(*args); end", "setter method 'foo=' cannot have more than one parameter"
assert_syntax_error "def foo=(**kwargs); end", "setter method 'foo=' cannot have more than one parameter"
assert_syntax_error "def foo=(&block); end", "setter method 'foo=' cannot have a block"
assert_syntax_error "def []=(&block); end", "setter method '[]=' cannot have a block"
assert_syntax_error "f.[]= do |a| end", "setter method '[]=' cannot be called with a block"
assert_syntax_error "f.[]= { |bar| }", "setter method '[]=' cannot be called with a block"

# #10397
%w(<= >= == != []= ===).each do |operator|
it_parses "def #{operator}(other, file = 1); end", Def.new(operator, ["other".arg, Arg.new("file", 1.int32)])
it_parses "def #{operator}(*args, **opts); end", Def.new(operator, ["args".arg], splat_index: 0, double_splat: "opts".arg)
it_parses "def #{operator}(*args, **opts, &); end", Def.new(operator, ["args".arg], splat_index: 0, double_splat: "opts".arg, block_arg: Arg.new(""), block_arity: 0)
end

# #5895, #6042, #5997
%w(
begin nil true false yield with abstract
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3658,8 +3658,8 @@ module Crystal

end_location = token_end_location

if name.ends_with?('=')
if name != "[]=" && (params.size > 1 || found_splat || found_double_splat)
if Lexer.setter?(name)
if params.size > 1 || found_splat || found_double_splat
raise "setter method '#{name}' cannot have more than one parameter"
elsif found_block
raise "setter method '#{name}' cannot have a block"
Expand Down