Skip to content

Commit 9f8334e

Browse files
Validate AliasMethodNode
1 parent 968ee09 commit 9f8334e

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,7 @@ nodes:
852852
kind:
853853
- SymbolNode
854854
- InterpolatedSymbolNode
855-
- on error: GlobalVariableReadNode # alias a $b
856-
- on error: ErrorRecoveryNode # alias a 42
855+
- on error: ErrorRecoveryNode
857856
comment: |
858857
Represents the old name of the method that will be aliased.
859858

src/prism.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18218,9 +18218,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1821818218
if (!PM_NODE_TYPE_P(old_name, PM_SYMBOL_NODE) && !PM_NODE_TYPE_P(old_name, PM_INTERPOLATED_SYMBOL_NODE)) {
1821918219
pm_parser_err_node(parser, old_name, PM_ERR_ALIAS_ARGUMENT);
1822018220
}
18221+
18222+
PM_VALIDATE_NODE_TYPE(parser, old_name, PM_SYMBOL_NODE, PM_INTERPOLATED_SYMBOL_NODE);
1822118223
}
1822218224
PRISM_FALLTHROUGH
1822318225
default:
18226+
PM_VALIDATE_NODE_TYPE(parser, old_name, PM_SYMBOL_NODE, PM_INTERPOLATED_SYMBOL_NODE);
1822418227
return UP(pm_alias_method_node_create(parser, &keyword, new_name, old_name));
1822518228
}
1822618229
}

test/prism/result/error_recovery_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def test_alias_method_node_old_name_global_variable
2727
refute result.success?
2828

2929
node = result.value.statements.body.first
30-
assert_kind_of GlobalVariableReadNode, node.old_name
30+
assert_kind_of ErrorRecoveryNode, node.old_name
31+
assert_kind_of GlobalVariableReadNode, node.old_name.child
3132
end
3233

3334
def test_alias_method_node_old_name_missing
@@ -36,6 +37,7 @@ def test_alias_method_node_old_name_missing
3637

3738
node = result.value.statements.body.first
3839
assert_kind_of ErrorRecoveryNode, node.old_name
40+
assert_nil node.old_name.child
3941
end
4042

4143
def test_class_node_constant_path_call

0 commit comments

Comments
 (0)