From 4ab175abb169d3541243f0023508477bc9b84be5 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Wed, 3 Jan 2024 01:22:52 +0800 Subject: [PATCH] Allow operators ending in `=` with multiple parameters --- spec/compiler/parser/parser_spec.cr | 5 +++++ src/compiler/crystal/syntax/parser.cr | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 41fad5cc3a89..5dae2efdc25d 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -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 diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index 751608468cd5..bbf5cade16b9 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -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"