Skip to content

Commit 082c0c9

Browse files
committed
Implement translation for it keyword
1 parent 74b5caa commit 082c0c9

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

parser/prism/Translator.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,14 @@ std::unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
862862
case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
863863
case PM_INTERPOLATED_SYMBOL_NODE:
864864
case PM_INTERPOLATED_X_STRING_NODE:
865-
case PM_IT_LOCAL_VARIABLE_READ_NODE:
866-
case PM_IT_PARAMETERS_NODE:
865+
case PM_IT_LOCAL_VARIABLE_READ_NODE: {
866+
// See Prism::ParserStorage::ParsedRubyVersion
867+
unreachable("The `it` keyword was introduced in Ruby 3.4, which isn't supported by Sorbet yet.");
868+
}
869+
case PM_IT_PARAMETERS_NODE: {
870+
// See Prism::ParserStorage::ParsedRubyVersion
871+
unreachable("The `it` keyword was introduced in Ruby 3.4, which isn't supported by Sorbet yet.");
872+
}
867873
case PM_LAMBDA_NODE:
868874
case PM_MATCH_LAST_LINE_NODE:
869875
case PM_MATCH_PREDICATE_NODE:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Begin {
2+
stmts = [
3+
Block {
4+
send = Send {
5+
receiver = Const {
6+
scope = NULL
7+
name = <C <U Proc>>
8+
}
9+
method = <U new>
10+
args = [
11+
]
12+
}
13+
args = NULL
14+
body = Send {
15+
receiver = NULL
16+
method = <U it>
17+
args = [
18+
]
19+
}
20+
}
21+
Block {
22+
send = Send {
23+
receiver = Const {
24+
scope = NULL
25+
name = <C <U Proc>>
26+
}
27+
method = <U new>
28+
args = [
29+
]
30+
}
31+
args = NULL
32+
body = Begin {
33+
stmts = [
34+
Assign {
35+
lhs = LVarLhs {
36+
name = <U it>
37+
}
38+
rhs = Integer {
39+
val = "123"
40+
}
41+
}
42+
LVar {
43+
name = <U it>
44+
}
45+
]
46+
}
47+
}
48+
]
49+
}

test/prism_regression/keyword_it.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# typed: false
2+
3+
# The `it` keyword was introduced in Ruby 3.4, which isn't supported by Sorbet yet.
4+
# https://bugs.ruby-lang.org/issues/18980
5+
#
6+
# For now, we'll just treat it like a local variable read or method call.
7+
8+
Proc.new do
9+
it # Prior to Ruby 3.4, this would just be a regular method call
10+
end
11+
12+
Proc.new do
13+
it = 123 # Prior to Ruby 3.4, this would just be a local variable write
14+
it # ... and this is a local variable read.
15+
end

0 commit comments

Comments
 (0)