class Crystal::MatchContext
inherits Reference
¶
Context information about a method lookup match.
For example, given:
class Foo
class Baz
end
def method
Baz.new
end
end
class Bar < Foo
class Baz
end
end
Bar.new.method # => #<Foo::Baz:0x10c1a2fc0>
we have that:
defining_type
isFoo
, because it's the type that define the methodinstantiated_type
isBar
, because the method was invoked, and thus instantiated there
defining_type
is needed because when we search types in method
,
we must search them starting from Foo
, not from Bar
.
instantiated_type
is needed because method resolution will start
from Bar
.
Todo
this might slightly change in the future, we should probably instantiate
the method on Foo+
to avoid having duplicated methods, at least for reference
types, even though that might lead to broader method resolutions (because
a method call in method
will now be searched in Foo+
, not in Bar
)
Class methods¶
.new(instantiated_type, defining_type, free_vars = nil, strict = false, def_free_vars = nil)
¶
(instantiated_type, defining_type, free_vars = nil, strict = false, def_free_vars = nil)
Methods¶
#def_free_vars=(def_free_vars : Array(String)?)
¶
(def_free_vars : Array(String)?)
Def free variables, unbound (def (X, Y) ...
)
#free_vars : Hash(String, TypeVar)?
¶
: Hash(String, TypeVar)?
Any instance variables associated with the method instantiation
#instantiated_type=(instantiated_type : Type)
¶
(instantiated_type : Type)
The type where the method was instantiated
#self_type : Type
¶
: Type
Returns the type that corresponds to using self
when looking
a type relative to this context.
For example, given:
class Foo
def foo(&block : self ->)
...
end
end
class Bar < Foo
end
Bar.new.foo { |x| }
it's expected that the block argument x
will be of type Bar
, not Foo
.