Skip to content

Commit

Permalink
Allow operators ending in = with multiple parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Jan 2, 2024
1 parent 316422f commit 4ab175a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ module Crystal
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)])
end

# #5895, #6042, #5997
%w(
begin nil true false yield with abstract
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3659,7 +3659,7 @@ 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) && (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

0 comments on commit 4ab175a

Please sign in to comment.