return self.modelbuilder.resolve_mtype(self.nclassdef, node)
end
+ fun try_get_mclass(node: ANode, name: String): nullable MClass
+ do
+ var mmodule = self.nclassdef.mclassdef.mmodule
+ var mclass = modelbuilder.try_get_mclass_by_name(node, mmodule, name)
+ return mclass
+ end
+
fun get_mclass(node: ANode, name: String): nullable MClass
do
var mmodule = self.nclassdef.mclassdef.mmodule
return null
end
+ if mproperty.visibility == protected_visibility and not recv_is_self and self.mmodule.visibility_for(mproperty.intro_mclassdef.mmodule) < intrude_visibility then
+ self.modelbuilder.error(node, "Error: Method '{name}' is protected and can only acceded by self. {mproperty.intro_mclassdef.mmodule.visibility_for(self.mmodule)}")
+ return null
+ end
+
var propdefs = mproperty.lookup_definitions(self.mmodule, unsafe_type)
if propdefs.length == 0 then
self.modelbuilder.error(node, "Type error: no definition found for property {name} in {unsafe_type}")
redef class AForExpr
var coltype: nullable MGenericType
- redef fun accept_typing(v)
- do
- var mtype = v.visit_expr(n_expr)
- if mtype == null then return
- var colcla = v.get_mclass(self, "Collection")
- if colcla == null then return
+ private fun do_type_iterator(v: TypeVisitor, mtype: MType)
+ do
var objcla = v.get_mclass(self, "Object")
if objcla == null then return
- var mapcla = v.get_mclass(self, "Map")
- if mapcla == null then return
- if v.is_subtype(mtype, colcla.get_mtype([objcla.mclass_type.as_nullable])) then
+
+ var colcla = v.try_get_mclass(self, "Collection")
+ if colcla != null and v.is_subtype(mtype, colcla.get_mtype([objcla.mclass_type.as_nullable])) then
var coltype = mtype.supertype_to(v.mmodule, v.anchor, colcla)
assert coltype isa MGenericType
self.coltype = coltype
else
variables.first.declared_type = coltype.arguments.first
end
- else if v.is_subtype(mtype, mapcla.get_mtype([objcla.mclass_type.as_nullable, objcla.mclass_type.as_nullable])) then
+ return
+ end
+
+ var mapcla = v.try_get_mclass(self, "Map")
+ if mapcla != null and v.is_subtype(mtype, mapcla.get_mtype([objcla.mclass_type.as_nullable, objcla.mclass_type.as_nullable])) then
var coltype = mtype.supertype_to(v.mmodule, v.anchor, mapcla)
assert coltype isa MGenericType
self.coltype = coltype
variables[0].declared_type = coltype.arguments[0]
variables[1].declared_type = coltype.arguments[1]
end
- else
- v.modelbuilder.error(self, "TODO: Do 'for' on {mtype}")
+ return
end
+ v.modelbuilder.error(self, "NOT YET IMPLEMENTED: Do 'for' on {mtype}")
+ end
+
+ redef fun accept_typing(v)
+ do
+ var mtype = v.visit_expr(n_expr)
+ if mtype == null then return
+
+ self.do_type_iterator(v, mtype)
+
v.visit_stmt(n_block)
self.is_typed = true
end
redef class ARangeExpr
redef fun accept_typing(v)
do
- var t1 = v.visit_expr(self.n_expr)
- var t2 = v.visit_expr(self.n_expr2)
+ var discrete_class = v.get_mclass(self, "Discrete")
+ if discrete_class == null then return # Forward error
+ var discrete_type = discrete_class.mclassdefs.first.bound_mtype
+ var t1 = v.visit_expr_subtype(self.n_expr, discrete_type)
+ var t2 = v.visit_expr_subtype(self.n_expr2, discrete_type)
if t1 == null or t2 == null then return
var mclass = v.get_mclass(self, "Range")
if mclass == null then return # Forward error
msignature = v.resolve_signature_for(msignature, recvtype, for_self)
var args = compute_raw_arguments
+ self.raw_arguments = args
v.check_signature(self, args, name, msignature)
private fun property_name: String is abstract
# An array of all arguments (excluding self)
- fun compute_raw_arguments: Array[AExpr] is abstract
+ var raw_arguments: nullable Array[AExpr]
+
+ private fun compute_raw_arguments: Array[AExpr] is abstract
end
redef class ABinopExpr
msignature = v.resolve_signature_for(msignature, recvtype, for_self)
var args = compute_raw_arguments
+ self.raw_arguments = args
v.check_signature(self, args, name, msignature)
var wtype = self.resolve_reassignment(v, readtype, wmsignature.mparameters.last.mtype)
if wtype == null then return
+ args = args.to_a # duplicate so raw_arguments keeps only the getter args
args.add(self.n_value)
v.check_signature(self, args, name + "=", wmsignature)