Skip to content
Open
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
19 changes: 16 additions & 3 deletions lib/typeprof/core/ast/sig_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,25 @@ def show
end

class SigTyIntersectionNode < SigTyNode
def initialize(raw_decl, lenv)
super(raw_decl, lenv)
@types = (raw_decl.types || []).map {|type| AST.create_rbs_type(type, lenv) }
end

attr_reader :types

def subnodes = { types: }

def covariant_vertex0(genv, changes, vtx, subst)
#raise NotImplementedError
@types.each do |type|
type.covariant_vertex0(genv, changes, vtx, subst)
end
end

def contravariant_vertex0(genv, changes, vtx, subst)
#raise NotImplementedError
@types.each do |type|
type.contravariant_vertex0(genv, changes, vtx, subst)
end
end

def typecheck(genv, changes, vtx, subst)
Expand All @@ -507,7 +520,7 @@ def typecheck(genv, changes, vtx, subst)
end

def show
"(...intersection...)"
@types.map {|ty| ty.show }.join(" & ")
end
end

Expand Down
39 changes: 39 additions & 0 deletions scenario/rbs/intersection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## update: test.rbs
interface _Readable
def read: () -> String
end

interface _Writable
def write: (String) -> void
end

class Processor
def process: (_Readable & _Writable) -> String
end

## update: test.rb
class MyIO
def read
"content"
end

def write(text)
text
end
end

class Processor
def process_file
io = MyIO.new
process(io)
end
end

## assert: test.rb
class MyIO
def read: -> String
def write: (untyped) -> untyped
end
class Processor
def process_file: -> String
end