Skip to content

Commit f148e3d

Browse files
sinsokuclaude
andcommitted
Fix NoMethodError in SigTyIntersectionNode typecheck method
- Add missing initialize method to properly initialize @types array - Implement covariant_vertex0 and contravariant_vertex0 methods - Fix show method to display intersection types correctly (using & separator) - Add test case for intersection type handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5d26f86 commit f148e3d

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

lib/typeprof/core/ast/sig_type.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,25 @@ def show
491491
end
492492

493493
class SigTyIntersectionNode < SigTyNode
494+
def initialize(raw_decl, lenv)
495+
super(raw_decl, lenv)
496+
@types = (raw_decl.types || []).map {|type| AST.create_rbs_type(type, lenv) }
497+
end
498+
499+
attr_reader :types
500+
501+
def subnodes = { types: }
502+
494503
def covariant_vertex0(genv, changes, vtx, subst)
495-
#raise NotImplementedError
504+
@types.each do |type|
505+
type.covariant_vertex0(genv, changes, vtx, subst)
506+
end
496507
end
497508

498509
def contravariant_vertex0(genv, changes, vtx, subst)
499-
#raise NotImplementedError
510+
@types.each do |type|
511+
type.contravariant_vertex0(genv, changes, vtx, subst)
512+
end
500513
end
501514

502515
def typecheck(genv, changes, vtx, subst)
@@ -507,7 +520,7 @@ def typecheck(genv, changes, vtx, subst)
507520
end
508521

509522
def show
510-
"(...intersection...)"
523+
@types.map {|ty| ty.show }.join(" & ")
511524
end
512525
end
513526

scenario/rbs/intersection.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## update: test.rbs
2+
interface _Readable
3+
def read: () -> String
4+
end
5+
6+
interface _Writable
7+
def write: (String) -> void
8+
end
9+
10+
class Processor
11+
def process: (_Readable & _Writable) -> String
12+
end
13+
14+
## update: test.rb
15+
class MyIO
16+
def read
17+
"content"
18+
end
19+
20+
def write(text)
21+
text
22+
end
23+
end
24+
25+
class Processor
26+
def process_file
27+
io = MyIO.new
28+
process(io)
29+
end
30+
end
31+
32+
## assert: test.rb
33+
class MyIO
34+
def read: -> String
35+
def write: (untyped) -> untyped
36+
end
37+
class Processor
38+
def process_file: -> String
39+
end

0 commit comments

Comments
 (0)