nitc :: ModelBuilder :: check_visibility
mtype
as an element of the signature of mpropdef
.
# Check the visibility of `mtype` as an element of the signature of `mpropdef`.
fun check_visibility(node: ANode, mtype: MType, mpropdef: MPropDef)
do
var mmodule = mpropdef.mclassdef.mmodule
var mproperty = mpropdef.mproperty
# Extract visibility information of the main part of `mtype`
# It is a case-by case
var vis_type: nullable MVisibility = null # The own visibility of the type
var mmodule_type: nullable MModule = null # The original module of the type
mtype = mtype.undecorate
if mtype isa MClassType then
vis_type = mtype.mclass.visibility
mmodule_type = mtype.mclass.intro_mmodule
else if mtype isa MVirtualType then
vis_type = mtype.mproperty.visibility
mmodule_type = mtype.mproperty.intro_mclassdef.mmodule
else if mtype isa MParameterType then
# nothing, always visible
else if mtype isa MNullType then
# nothing to do.
else if mtype isa MBottomType then
# nothing to do.
else if mtype isa MErrorType then
# nothing to do.
else
node.debug "Unexpected type {mtype}"
abort
end
if vis_type != null then
assert mmodule_type != null
var vis_module_type = mmodule.visibility_for(mmodule_type) # the visibility of the original module
if mproperty.visibility > vis_type then
error(node, "Error: the {mproperty.visibility} property `{mproperty}` cannot contain the {vis_type} type `{mtype}`.")
return
else if mproperty.visibility > vis_module_type then
error(node, "Error: the {mproperty.visibility} property `{mproperty}` cannot contain the type `{mtype}` from the {vis_module_type} module `{mmodule_type}`.")
return
end
end
# No error, try to go deeper in generic types
if node isa AType then
for a in node.n_types do
var t = a.mtype
if t == null then continue # Error, thus skipped
check_visibility(a, t, mpropdef)
end
else if mtype isa MGenericType then
for t in mtype.arguments do check_visibility(node, t, mpropdef)
end
end
src/modelize/modelize_property.nit:391,2--443,4