Skip to content

Commit 6c06ab8

Browse files
pvcresincursoragent
authored andcommitted
Fix fcall include handling with context-aware meta parsing
Limit include/attr_* meta parsing to class/module top-level statements and add a regression scenario for fcall include. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 80a0f5f commit 6c06ab8

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

lib/typeprof/core/ast.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def self.parse_rb(path, src)
1818
ProgramNode.new(raw_scope, lenv)
1919
end
2020

21-
#: (untyped, TypeProf::Core::LocalEnv, ?bool) -> TypeProf::Core::AST::Node
22-
def self.create_node(raw_node, lenv, use_result = true)
21+
#: (untyped, TypeProf::Core::LocalEnv, ?bool, ?bool) -> TypeProf::Core::AST::Node
22+
def self.create_node(raw_node, lenv, use_result = true, allow_meta = false)
2323
while true
2424
case raw_node.type
2525
when :parentheses_node
@@ -233,8 +233,7 @@ def self.create_node(raw_node, lenv, use_result = true)
233233
when :forwarding_super_node then ForwardingSuperNode.new(raw_node, lenv)
234234
when :yield_node then YieldNode.new(raw_node, lenv)
235235
when :call_node
236-
if !raw_node.receiver
237-
# TODO: handle them only when it is directly under class or module
236+
if allow_meta && !raw_node.receiver && !lenv.cref.mid && [:class, :metaclass].include?(lenv.cref.scope_level)
238237
case raw_node.name
239238
when :include
240239
return IncludeMetaNode.new(raw_node, lenv)

lib/typeprof/core/ast/misc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def initialize(raw_node, lenv, use_result)
66
stmts = raw_node.body
77
@stmts = stmts.map.with_index do |n, i|
88
if n
9-
AST.create_node(n, lenv, i == stmts.length - 1 ? use_result : false)
9+
AST.create_node(n, lenv, i == stmts.length - 1 ? use_result : false, true)
1010
else
1111
last = code_range.last
1212
DummyNilNode.new(TypeProf::CodeRange.new(last, last), lenv)

0 commit comments

Comments
 (0)