summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroya Fujinami <make.just.on@gmail.com>2023-11-22 02:03:29 +0900
committergit <svn-admin@ruby-lang.org>2023-11-21 17:03:33 +0000
commitad25313ca813eda99ac5ae56544a3ec9411f342e (patch)
treec47a8022a6335f0f5a2317b88a76295b5fcc4875
parent0aafd040c3fee4ad2b5dde4b58c1a4f1ee7ace18 (diff)
[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 <kddnewton@gmail.com>
-rw-r--r--prism/prism.c10
-rw-r--r--test/prism/errors_test.rb8
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"