X-Git-Url: http://nitlanguage.org diff --git a/src/modelize_property.nit b/src/modelize_property.nit index 1245af5..9425fcf 100644 --- a/src/modelize_property.nit +++ b/src/modelize_property.nit @@ -150,6 +150,50 @@ redef class ModelBuilder nclassdef.mfree_init = mpropdef self.toolcontext.info("{mclassdef} gets a free constructor for attributes {mpropdef}{msignature}", 3) end + + # 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 origial module of the type + if mtype isa MNullableType then mtype = mtype.mtype + 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 + 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 check_visibility(a, a.mtype.as(not null), mpropdef) + else if mtype isa MGenericType then + for t in mtype.arguments do check_visibility(node, t, mpropdef) + end + end end redef class MClass @@ -510,6 +554,7 @@ redef class AMethPropdef msignature = new MSignature(mparameters, ret_type) mpropdef.msignature = msignature mpropdef.is_abstract = self isa ADeferredMethPropdef + mpropdef.is_intern = self isa AInternMethPropdef end redef fun check_signature(modelbuilder, nclassdef) @@ -554,6 +599,16 @@ redef class AMethPropdef end end end + + if mysignature.arity > 0 then + # Check parameters visibility + for i in [0..mysignature.arity[ do + var nt = nsig.n_params[i].n_type + if nt != null then modelbuilder.check_visibility(nt, nt.mtype.as(not null), mpropdef) + end + var nt = nsig.n_type + if nt != null then modelbuilder.check_visibility(nt, nt.mtype.as(not null), mpropdef) + end end end @@ -798,9 +853,19 @@ redef class AAttrPropdef # Check getter and setter var meth = self.mreadpropdef - if meth != null then self.check_method_signature(modelbuilder, nclassdef, meth) + if meth != null then + self.check_method_signature(modelbuilder, nclassdef, meth) + var node: nullable ANode = ntype + if node == null then node = self + modelbuilder.check_visibility(node, mtype, meth) + end meth = self.mwritepropdef - if meth != null then self.check_method_signature(modelbuilder, nclassdef, meth) + if meth != null then + self.check_method_signature(modelbuilder, nclassdef, meth) + var node: nullable ANode = ntype + if node == null then node = self + modelbuilder.check_visibility(node, mtype, meth) + end end private fun check_method_signature(modelbuilder: ModelBuilder, nclassdef: AClassdef, mpropdef: MMethodDef) @@ -869,7 +934,7 @@ redef class ATypePropdef if mprop == null then var mvisibility = new_property_visibility(modelbuilder, nclassdef, self.n_visibility) mprop = new MVirtualTypeProp(mclassdef, name, mvisibility) - for c in name do if c >= 'a' and c<= 'z' then + for c in name.chars do if c >= 'a' and c<= 'z' then modelbuilder.warning(n_id, "Warning: lowercase in the virtual type {name}") break end @@ -907,6 +972,9 @@ redef class ATypePropdef if mpropdef == null then return # Error thus skiped var bound = self.mpropdef.bound + if bound == null then return # Error thus skiped + + modelbuilder.check_visibility(n_type.as(not null), bound, mpropdef) # Fast case: the bound is not a formal type if not bound isa MVirtualType then return @@ -924,7 +992,7 @@ redef class ATypePropdef end seen.add(bound) var next = bound.lookup_bound(mmodule, anchor) - if not next isa MVirtualType then return + if not next isa MVirtualType then break bound = next end end