This is an helper function for lookup_definitions
and lookup_super_definitions
# Return an array containing olny the most specific property definitions
# This is an helper function for `lookup_definitions` and `lookup_super_definitions`
private fun select_most_specific(mmodule: MModule, candidates: Array[MPROPDEF]): Array[MPROPDEF]
do
var res = new Array[MPROPDEF]
for pd1 in candidates do
var cd1 = pd1.mclassdef
var c1 = cd1.mclass
var keep = true
for pd2 in candidates do
if pd2 == pd1 then continue # do not compare with self!
var cd2 = pd2.mclassdef
var c2 = cd2.mclass
if c2.mclass_type == c1.mclass_type then
if cd2.mmodule.in_importation < cd1.mmodule then
# cd2 refines cd1; therefore we skip pd1
keep = false
break
end
else if cd2.bound_mtype.is_subtype(mmodule, null, cd1.bound_mtype) and cd2.bound_mtype != cd1.bound_mtype then
# cd2 < cd1; therefore we skip pd1
keep = false
break
end
end
if keep then
res.add(pd1)
end
end
if res.is_empty then
print_error "All lost! {candidates.join(", ")}"
# FIXME: should be abort!
end
return res
end
src/model/model.nit:2306,2--2340,4