is_valid is used to discriminate fully build MMType from others.
Currently, only MMTypeFormal require it.
Previous behavior of returning null on invalid MMTypeFormal's methods is disabled.
syntax_base.nit is adapted to the new behavior.
Signed-off-by: Jean Privat <jean@pryen.org>
# The local class that self direclty or indirectly refers to
meth local_class: MMLocalClass is abstract
+ # Is the type a valid one
+ # For instance, circular dependency on formal types is invalid
+ meth is_valid: Bool do return true
+
# Is self a valid subtype of t
meth <(t : MMType): Bool is abstract
# Formal types are named indirect types
class MMTypeFormal
special MMType
+ redef meth is_valid do return _bound != null
+
# The name of the type
readable attr _name: Symbol
# The type refered
- readable attr _bound: MMType
+ meth bound: MMType
+ do
+ assert is_valid
+ return _bound
+ end
+ attr _bound: MMType
redef meth <(t) do return t != null and (t == self or t.is_supertype(_bound))
redef meth is_supertype(t) do return _bound.is_supertype(t)
redef meth direct_type do return _bound.direct_type
- redef meth local_class
- do
- if _bound == null then return null
- return _bound.local_class
- end
+ redef meth local_class do return _bound.local_class
redef meth to_s do return _name.to_s
redef meth get_stype(v)
do
var t = get_unchecked_stype(v)
- if t != null then check_conform(v)
+ if t == null then return null
+ if not t.is_valid then return null
+ check_conform(v)
return t
end
for i in [0..arity[ do
var p = n_types[i]
var pt = p.get_stype(v)
- var bt = local_class.get_formal(i).bound
- if bt == null then return
+ var b = local_class.get_formal(i)
+ if not b.is_valid then return
+ var bt = b.bound
bt = bt.adapt_to(st) # We need to abapt because of F-genericity
v.check_conform(p, pt, bt)
end