- var candidates = self.lookup_definitions(mmodule, mtype)
- if candidates.length == 1 then return candidates.first
- assert candidates.length > 0
+ # Return all definitions in a linearisation order
+ # Most speficic first, most general last
+ fun lookup_all_definitions(mmodule: MModule, mtype: MType): Array[MPROPDEF]
+ do
+ assert not mtype.need_anchor
+ if mtype isa MNullableType then mtype = mtype.mtype
+
+ var cache = self.lookup_all_definitions_cache[mmodule, mtype]
+ if cache != null then return cache
+
+ #print "select prop {mproperty} for {mtype} in {self}"
+ # First, select all candidates
+ var candidates = new Array[MPROPDEF]
+ for mpropdef in self.mpropdefs do
+ # If the definition is not imported by the module, then skip
+ if not mmodule.in_importation <= mpropdef.mclassdef.mmodule then continue
+ # If the definition is not inherited by the type, then skip
+ if not mtype.is_subtype(mmodule, null, mpropdef.mclassdef.bound_mtype) then continue
+ # Else, we keep it
+ candidates.add(mpropdef)
+ end
+ # Fast track for only one candidate
+ if candidates.length <= 1 then
+ self.lookup_all_definitions_cache[mmodule, mtype] = candidates
+ return candidates
+ end