+ # Generate type checks in the C code to check covariant parameters
+ fun parameter_check(node: ANode, mpropdef: MMethodDef, args: Array[Instance])
+ do
+ var msignature = mpropdef.msignature
+ for i in [0..msignature.arity[ do
+ # skip test for vararg since the array is instantiated with the correct polymorphic type
+ if msignature.vararg_rank == i then continue
+
+ # skip if the cast is not required
+ var origmtype = mpropdef.mproperty.intro.msignature.mparameters[i].mtype
+ if not origmtype.need_anchor then continue
+
+ # get the parameter type
+ var mtype = msignature.mparameters[i].mtype
+ var anchor = args.first.mtype.as(MClassType)
+ mtype = mtype.anchor_to(self.mainmodule, anchor)
+ if not args[i+1].mtype.is_subtype(self.mainmodule, anchor, mtype) then
+ node.fatal(self, "Cast failed")
+ end
+ end
+ end
+
+ fun call_closure(closure: ClosureInstance, args: Array[Instance]): nullable Instance
+ do
+ var nclosuredef = closure.nclosuredef
+ var f = closure.frame
+ for i in [0..closure.nclosuredef.mclosure.mtype.as(MSignature).arity[ do
+ var variable = nclosuredef.variables[i]
+ f.map[variable] = args[i]
+ end
+
+ self.frames.unshift(f)
+
+ self.stmt(nclosuredef.n_expr)
+
+ self.frames.shift
+
+ if self.is_continue(nclosuredef.escapemark) then
+ var res = self.escapevalue
+ self.escapevalue = null
+ return res
+ end
+ return null
+ end
+