nitc :: APropdef :: check_signature
private fun check_signature(modelbuilder: ModelBuilder) do end
src/modelize/modelize_property.nit:588,2--63
redef fun check_signature(modelbuilder)
do
var mpropdef = self.mpropdef
if mpropdef == null then return # Error thus skipped
var ntype = self.n_type
var mtype = self.mtype
if mtype == null then return # Error thus skipped
var mclassdef = mpropdef.mclassdef
var mmodule = mclassdef.mmodule
# Check types
if ntype != null then
if modelbuilder.resolve_mtype(mclassdef, ntype) == null then return
end
var nexpr = n_expr
if nexpr isa ANewExpr then
if modelbuilder.resolve_mtype(mclassdef, nexpr.n_type) == null then return
end
# Lookup for signature in the precursor
# FIXME all precursors should be considered
if not mpropdef.is_intro then
var precursor_type = mpropdef.mproperty.intro.static_mtype
if precursor_type == null then return
if mtype != precursor_type then
modelbuilder.error(ntype.as(not null), "Redef Error: expected `{precursor_type}` type as a bound; got `{mtype}`.")
return
end
end
# Check getter and setter
var meth = self.mreadpropdef
if meth != null then
self.check_method_signature(modelbuilder, 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, meth)
var node: nullable ANode = ntype
if node == null then node = self
modelbuilder.check_visibility(node, mtype, meth)
end
end
src/modelize/modelize_property.nit:1671,2--1718,4
redef fun check_signature(modelbuilder)
do
var mpropdef = self.mpropdef
if mpropdef == null then return # Error thus skipped
var bound = mpropdef.bound
if bound == null then return # Error thus skipped
modelbuilder.check_visibility(n_type, bound, mpropdef)
var mclassdef = mpropdef.mclassdef
var mmodule = mclassdef.mmodule
var anchor = mclassdef.bound_mtype
var ntype = self.n_type
if modelbuilder.resolve_mtype(mclassdef, ntype) == null then
mpropdef.bound = null
return
end
# Check redefinitions
for p in mpropdef.mproperty.lookup_super_definitions(mmodule, anchor) do
var supbound = p.bound
if supbound == null or supbound isa MBottomType or p.is_broken then break # broken super bound, skip error
if p.is_fixed then
modelbuilder.error(self, "Redef Error: virtual type `{mpropdef.mproperty}` is fixed in super-class `{p.mclassdef.mclass}`.")
break
end
if p.mclassdef.mclass == mclassdef.mclass then
modelbuilder.error(n_type, "Redef Error: a virtual type cannot be refined.")
break
end
if not modelbuilder.check_subtype(n_type, mmodule, anchor, bound, supbound) then
modelbuilder.error(n_type, "Redef Error: expected `{supbound}` bound type; got `{bound}`.")
break
end
end
end
src/modelize/modelize_property.nit:1851,2--1888,4
redef fun check_signature(modelbuilder)
do
var mpropdef = self.mpropdef
if mpropdef == null then return # Error thus skiped
var mclassdef = mpropdef.mclassdef
var mmodule = mclassdef.mmodule
var nsig = self.n_signature
var mysignature = mpropdef.msignature
if mysignature == null then return # Error thus skiped
# Check
if nsig != null then
if not nsig.check_signature(modelbuilder, mclassdef) then
mpropdef.msignature = null # invalidate
mpropdef.is_broken = true
return # Forward error
end
end
# Lookup for signature in the precursor
# FIXME all precursors should be considered
if not mpropdef.is_intro then
var msignature = mpropdef.mproperty.intro.msignature
if msignature == null then return
var precursor_ret_type = msignature.return_mtype
var ret_type = mysignature.return_mtype
if ret_type != null and precursor_ret_type == null then
modelbuilder.error(nsig.n_type, "Redef Error: `{mpropdef.mproperty}` is a procedure, not a function.")
mpropdef.msignature = null
mpropdef.is_broken = true
return
end
if mysignature.arity > 0 then
# Check parameters types
for i in [0..mysignature.arity[ do
var myt = mysignature.mparameters[i].mtype
var prt = msignature.mparameters[i].mtype
var node = nsig.n_params[i]
if not modelbuilder.check_sametype(node, mmodule, mclassdef.bound_mtype, myt, prt) then
modelbuilder.error(node, "Redef Error: expected `{prt}` for parameter `{mysignature.mparameters[i].name}'; got `{myt}`.")
mpropdef.msignature = null
mpropdef.is_broken = true
end
end
end
if precursor_ret_type != null then
var node: nullable ANode = null
if nsig != null then node = nsig.n_type
if node == null then node = self
if ret_type == null then
# Inherit the return type
ret_type = precursor_ret_type
else if not modelbuilder.check_subtype(node, mmodule, mclassdef.bound_mtype, ret_type, precursor_ret_type) then
modelbuilder.error(node, "Redef Error: expected `{precursor_ret_type}` for return type; got `{ret_type}`.")
mpropdef.msignature = null
mpropdef.is_broken = true
end
end
end
if nsig != null 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
check_repeated_types(modelbuilder)
end
src/modelize/modelize_property.nit:1027,2--1099,4