Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/typeprof/core/ast/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ def define0(genv)
end
if @kind == :struct
# Struct.[] calls the receiver's initialize, like Class#new
genv.resolve_method(struct_base_cpath, true, :[]).builtin = Builtin.new(genv).method(:class_new)
me = genv.resolve_method(struct_base_cpath, true, :[])
unless me.builtin
me.builtin = Builtin.new(genv).method(:class_new)
# Unlike a method definition, a builtin does not notify the calls itself
me.add_run_all_method_call_boxes(genv)
end
end
@block_body.define(genv) if @block_body
cdef
Expand Down Expand Up @@ -358,7 +363,9 @@ def undefine0(genv)
end
# On an update, the new node has already set the builtin
if base.module_defs.to_a.none? { _1.kind == :struct }
genv.resolve_method(struct_base_cpath, true, :[]).builtin = nil
me = genv.resolve_method(struct_base_cpath, true, :[])
me.builtin = nil
me.add_run_all_method_call_boxes(genv)
end
@block_body.undefine(genv) if @block_body
end
Expand Down
35 changes: 35 additions & 0 deletions scenario/incremental/struct-aref-to-data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## update
Pt = Struct.new(:x, :y)
def f = Pt[1, 2]

## diagnostics

## assert
class Pt
def x: -> Integer
def x=: (untyped) -> untyped
def y: -> Integer
def y=: (untyped) -> untyped
def initialize: (?Integer, ?Integer) -> void
def self.[]: (?Integer, ?Integer) -> Pt
end
class Object
def f: -> Pt
end

## update
Pt = Data.define(:x, :y)
def f = Pt[1, 2]

## diagnostics
(2,10)-(2,16): undefined method: singleton(Pt)#[]

## assert
class Pt
def x: -> untyped
def y: -> untyped
def initialize: (x: untyped, y: untyped) -> void
end
class Object
def f: -> untyped
end
Loading