From ad25313ca813eda99ac5ae56544a3ec9411f342e Mon Sep 17 00:00:00 2001 From: Hiroya Fujinami Date: Wed, 22 Nov 2023 02:03:29 +0900 Subject: [PATCH] [ruby/prism] Fix `..` and `...` to be non-associative (https://github.com/ruby/prism/pull/1837) Fix https://github.com/ruby/prism/pull/1829 https://github.com/ruby/prism/commit/90b0b1974c Co-authored-by: Kevin Newton --- prism/prism.c | 10 ++++------ test/prism/errors_test.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/prism/prism.c b/prism/prism.c index bf048f1883..eac746ef74 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -10141,10 +10141,8 @@ typedef struct { bool binary; /** - * Whether or not this token can be used as non associative binary operator. - * Usually, non associative operator can be handled by using the above left - * and right binding powers, but some operators (e.g. in and =>) need special - * treatment since they do not call parse_expression recursively. + * Whether or not this token can be used as non-associative binary operator. + * Non-associative operators (e.g. in and =>) need special treatment in parse_expression. */ bool nonassoc; } pm_binding_powers_t; @@ -10193,8 +10191,8 @@ pm_binding_powers_t pm_binding_powers[PM_TOKEN_MAXIMUM] = { [PM_TOKEN_QUESTION_MARK] = RIGHT_ASSOCIATIVE(PM_BINDING_POWER_TERNARY), // .. ... - [PM_TOKEN_DOT_DOT] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_RANGE), - [PM_TOKEN_DOT_DOT_DOT] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_RANGE), + [PM_TOKEN_DOT_DOT] = NON_ASSOCIATIVE(PM_BINDING_POWER_RANGE), + [PM_TOKEN_DOT_DOT_DOT] = NON_ASSOCIATIVE(PM_BINDING_POWER_RANGE), // || [PM_TOKEN_PIPE_PIPE] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_LOGICAL_OR), diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index 9362032fe3..99b799d9c5 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -1708,6 +1708,14 @@ module Prism ] end + def test_non_assoc_range + source = '1....2' + assert_errors expression(source), source, [ + ['Expected a newline or semicolon after the statement', 4..4], + ['Cannot parse the expression', 4..4], + ] + end + def test_upcase_end_in_def assert_warning_messages "def foo; END { }; end", [ "END in method; use at_exit"