- # Register the nclassdef associated to each mclassdef
- # FIXME: why not refine the `MClassDef` class with a nullable attribute?
- var mclassdef2nclassdef: HashMap[MClassDef, AClassdef] = new HashMap[MClassDef, AClassdef]
-
- # Return the static type associated to the node `ntype`.
- # `mmodule` and `mclassdef` is the context where the call is made (used to understand formal types)
- # In case of problem, an error is displayed on `ntype` and null is returned.
- # FIXME: the name "resolve_mtype" is awful
- fun resolve_mtype_unchecked(mmodule: MModule, mclassdef: nullable MClassDef, ntype: AType, with_virtual: Bool): nullable MType
- do
- var name = ntype.n_id.text
- var res: MType
-
- # Check virtual type
- if mclassdef != null and with_virtual then
- 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.")
- end
- res = prop.mvirtualtype
- if ntype.n_kwnullable != null then res = res.as_nullable
- ntype.mtype = res
- return res
- end
- end
-
- # Check parameter type
- if mclassdef != null and mclassdef.parameter_names.has(name) then
- if not ntype.n_types.is_empty then
- error(ntype, "Type error: formal type {name} cannot have formal parameters.")
- end
- for i in [0..mclassdef.parameter_names.length[ do
- if mclassdef.parameter_names[i] == name then
- res = mclassdef.mclass.mclass_type.arguments[i]
- if ntype.n_kwnullable != null then res = res.as_nullable
- ntype.mtype = res
- return res
- end
- end
- abort
- end