if res == null then
res = mclass
else
- error(anode, "Ambigous class name '{name}'; conflict between {mclass.full_name} and {res.full_name}")
+ error(anode, "Error: ambiguous class name `{name}`; conflict between `{mclass.full_name}` and `{res.full_name}`.")
return null
end
end
return res
end
+ # Like `try_get_mclass_by_name` but display an error message when the class is not found
+ fun get_mclass_by_name(node: ANode, mmodule: MModule, name: String): nullable MClass
+ do
+ var mclass = try_get_mclass_by_name(node, mmodule, name)
+ if mclass == null then
+ error(node, "Type Error: missing primitive class `{name}'.")
+ end
+ return mclass
+ end
+
# Return a property named `name` on the type `mtype` visible in the module `mmodule`.
# Visibility in modules is correctly handled.
# Protected properties are returned (it is up to the caller to check and reject protected properties).
assert ress.length > 1
var s = new Array[String]
for mprop in ress do s.add mprop.full_name
- self.error(anode, "Ambigous property name '{name}' for {mtype}; conflict between {s.join(" and ")}")
+ self.error(anode, "Error: ambiguous property name `{name}` for `{mtype}`; conflict between {s.join(" and ")}.")
end
self.try_get_mproperty_by_name2_cache[mmodule, mtype, name] = res
if res == null then
var l = null
if n != null then l = n.hot_location
- self.toolcontext.fatal_error(l, "Fatal Error: {recv} must have a property named {name}.")
+ self.toolcontext.fatal_error(l, "Fatal Error: `{recv}` must have a property named `{name}`.")
abort
end
return res
var prop = try_get_mproperty_by_name(ntype, mclassdef, name).as(nullable MVirtualTypeProp)
if prop != null then
if not ntype.n_types.is_empty then
- error(ntype, "Type error: formal type {name} cannot have formal parameters.")
+ error(ntype, "Type Error: formal type `{name}` cannot have formal parameters.")
end
res = prop.mvirtualtype
if ntype.n_kwnullable != null then res = res.as_nullable
if p.name != name then continue
if not ntype.n_types.is_empty then
- error(ntype, "Type error: formal type {name} cannot have formal parameters.")
+ error(ntype, "Type Error: formal type `{name}` cannot have formal parameters.")
end
res = p
var arity = ntype.n_types.length
if arity != mclass.arity then
if arity == 0 then
- error(ntype, "Type error: '{name}' is a generic class.")
+ error(ntype, "Type Error: `{mclass.signature_to_s}` is a generic class.")
else if mclass.arity == 0 then
- error(ntype, "Type error: '{name}' is not a generic class.")
+ error(ntype, "Type Error: `{name}` is not a generic class.")
else
- error(ntype, "Type error: '{name}' has {mclass.arity} parameters ({arity} are provided).")
+ error(ntype, "Type Error: expected {mclass.arity} formal argument(s) for `{mclass.signature_to_s}`; got {arity}.")
end
return null
end
end
# If everything fail, then give up :(
- error(ntype, "Type error: class {name} not found in module {mmodule}.")
+ error(ntype, "Error: class `{name}` not found in module `{mmodule}`.")
return null
end
if mtype isa MGenericType then
var mclass = mtype.mclass
for i in [0..mclass.arity[ do
- var bound = mclass.intro.bound_mtype.arguments[i]
+ var intro = mclass.try_intro
+ if intro == null then return null # skip error
+ var bound = intro.bound_mtype.arguments[i]
var nt = ntype.n_types[i]
var mt = resolve_mtype(mmodule, mclassdef, nt)
if mt == null then return null # forward error
var anchor
if mclassdef != null then anchor = mclassdef.bound_mtype else anchor = null
- if not mt.is_subtype(mmodule, anchor, bound) then
- error(nt, "Type error: expected {bound}, got {mt}")
+ if not check_subtype(nt, mmodule, anchor, mt, bound) then
+ error(nt, "Type Error: expected `{bound}`, got `{mt}`.")
return null
end
end
ntype.checked_mtype = true
return mtype
end
+
+ # Check that `sub` is a subtype of `sup`.
+ # Do not display an error message.
+ #
+ # This method is used a an entry point for the modelize phase to test static subtypes.
+ # Some refinements could redefine it to collect statictics.
+ fun check_subtype(node: ANode, mmodule: MModule, anchor: nullable MClassType, sub, sup: MType): Bool
+ do
+ return sub.is_subtype(mmodule, anchor, sup)
+ end
+
+ # Check that `sub` and `sup` are equvalent types.
+ # Do not display an error message.
+ #
+ # This method is used a an entry point for the modelize phase to test static equivalent types.
+ # Some refinements could redefine it to collect statictics.
+ fun check_sametype(node: ANode, mmodule: MModule, anchor: nullable MClassType, sub, sup: MType): Bool
+ do
+ return sub.is_subtype(mmodule, anchor, sup) and sup.is_subtype(mmodule, anchor, sub)
+ end
end
redef class AType
do
var res = mdoc_cache
if res != null then return res
- res = new MDoc
+ res = new MDoc(location)
for c in n_comment do
var text = c.text
if text.length < 2 then