do
if v.compiler.modelbuilder.toolcontext.opt_no_check_covariance.value then return
+ var msignature = self.msignature.as(not null)
+
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
if not origmtype.need_anchor then continue
# get the parameter type
- var mtype = self.msignature.mparameters[i].mtype
+ var mtype = msignature.mparameters[i].mtype
# generate the cast
# note that v decides if and how to implements the cast
- v.add("/* Covariant cast for argument {i} ({self.msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
+ v.add("/* Covariant cast for argument {i} ({msignature.mparameters[i].name}) {arguments[i+1].inspect} isa {mtype} */")
v.add_cast(arguments[i+1], mtype, "covariance")
end
end
redef class ASuperExpr
redef fun expr(v)
do
- var recv = v.frame.arguments.first
+ var frame = v.frame.as(not null)
+ var recv = frame.arguments.first
var callsite = self.callsite
if callsite != null then
# Add automatic arguments for the super init call
args = [recv]
for i in [0..callsite.msignature.arity[ do
- args.add(v.frame.arguments[i+1])
+ args.add(frame.arguments[i+1])
end
else
args = v.varargize(callsite.mpropdef, callsite.signaturemap, recv, self.n_args.n_exprs)
var args
if self.n_args.n_exprs.is_empty then
- args = v.frame.arguments
+ args = frame.arguments
else
args = v.varargize(mpropdef, signaturemap, recv, self.n_args.n_exprs)
end
var res = v.new_var(mtype)
res.is_exact = true
if is_native_array then
- var mtype_elt = mtype.arguments.first
v.add("{res} = nit_alloc(sizeof(struct {mtype.c_name}) + length*sizeof(val*));")
v.add("((struct {mtype.c_name}*){res})->length = length;")
else
n.debug("inconsitance: no value and not escaping.")
end
var implicit_cast_to = n.implicit_cast_to
- if implicit_cast_to != null then
+ if i != null and implicit_cast_to != null then
var mtype = self.unanchor_type(implicit_cast_to)
if not self.is_subtype(i.mtype, mtype) then n.fatal(self, "Cast failed. Expected `{implicit_cast_to}`, got `{i.mtype}`")
end
# Execute type checks of covariant parameters
fun parameter_check(node: ANode, mpropdef: MMethodDef, args: Array[Instance])
do
- var msignature = mpropdef.msignature
+ var msignature = mpropdef.msignature.as(not null)
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
# Use this method, instead of `send` to execute and control the additional behavior of the call-sites
fun callsite(callsite: nullable CallSite, arguments: Array[Instance]): nullable Instance
do
+ if callsite == null then return null
var initializers = callsite.mpropdef.initializers
if not initializers.is_empty then
var recv = arguments.first
redef fun mdoc_or_fallback
do
if mdoc != null then return mdoc
+ var default_mmodule = self.default_mmodule
if default_mmodule == null then return null
return default_mmodule.mdoc_or_fallback
end
do
model.mmodules_by_name.add_one(name, self)
model.mmodules.add(self)
+ var mgroup = self.mgroup
if mgroup != null then
mgroup.mmodules.add(self)
if mgroup.name == name then
end
print("Fatal Error: no primitive class {name} in {self}")
exit(1)
+ abort
end
if cla.length != 1 then
var msg = "Fatal Error: more than one primitive class {name} in {self}:"
end
if resolved_receiver isa MNullableType then resolved_receiver = resolved_receiver.mtype
if resolved_receiver isa MParameterType then
+ assert anchor != null
assert resolved_receiver.mclass == anchor.mclass
resolved_receiver = anchor.arguments[resolved_receiver.rank]
if resolved_receiver isa MNullableType then resolved_receiver = resolved_receiver.mtype
redef fun display(a) do
if a isa MGroup then
- if a.parent == null then return "{a.mpackage.name} ({a.filepath.to_s})"
+ if a.parent == null then return "{a.mpackage.name} ({a.filepath or else "?"})"
return a.name + " (group)"
else if a isa MModule then
return a.name
var subs = tree.sub[o]
var minres = mini(subs.first)
var maxres = maxi(subs.first)
- var order = minres.model.mmodule_importation_hierarchy
+ var order = o.model.mmodule_importation_hierarchy
for o2 in subs do
var c = mini(o2)
if c == null then continue
if mgroup.parent == null then
# is is a root group, so display the package
if package_group then
- o.write("subgraph cluster_{mgroup.object_id} \{\nlabel=\"{mgroup.mpackage.name}\\n({mgroup.filepath.to_s})\"\ncolor=black\nstyle=dotted\n")
+ o.write("subgraph cluster_{mgroup.object_id} \{\nlabel=\"{mgroup.mpackage.name}\\n({mgroup.filepath or else "?"})\"\ncolor=black\nstyle=dotted\n")
end
else
if cluster_group then
for npropdef in nclassdef.n_propdefs do
if npropdef isa AMethPropdef then
if not npropdef.is_autoinit then continue # Skip non tagged autoinit
- if npropdef.mpropdef == null then return # Skip broken method
- var sig = npropdef.mpropdef.msignature
+ var mpropdef = npropdef.mpropdef
+ if mpropdef == null then return # Skip broken method
+ var sig = mpropdef.msignature
if sig == null then continue # Skip broken method
for param in sig.mparameters do
var mparameter = new MParameter(param.name, ret_type, false)
mparameters.add(mparameter)
end
- initializers.add(npropdef.mpropdef.mproperty)
- npropdef.mpropdef.mproperty.is_autoinit = true
+ initializers.add(mpropdef.mproperty)
+ mpropdef.mproperty.is_autoinit = true
end
if npropdef isa AAttrPropdef then
var mreadpropdef = npropdef.mreadpropdef
- if mreadpropdef == null or mreadpropdef.msignature == null then return # Skip broken attribute
+ if mreadpropdef == null then return # Skip broken attribute
+ var msignature = mreadpropdef.msignature
+ if msignature == null then return # Skip broken attribute
if npropdef.noinit then continue # Skip noinit attribute
var atlateinit = npropdef.get_single_annotation("lateinit", self)
if atlateinit != null then
end
if npropdef.has_value then continue
var paramname = mreadpropdef.mproperty.name
- var ret_type = mreadpropdef.msignature.return_mtype
+ var ret_type = msignature.return_mtype
if ret_type == null then return
var mparameter = new MParameter(paramname, ret_type, false)
mparameters.add(mparameter)
end
end
+ var the_root_init_mmethod = self.the_root_init_mmethod
if the_root_init_mmethod == null then return
# Look for most-specific new-stype init definitions
end
# Else create the local implicit basic init definition
- var mprop = the_root_init_mmethod.as(not null)
+ var mprop = the_root_init_mmethod
var mpropdef = new MMethodDef(mclassdef, mprop, nclassdef.location)
mpropdef.has_supercall = true
mpropdef.initializers.add_all(initializers)
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.as(not null), "Redef Error: `{mpropdef.mproperty}` is a procedure, not a function.")
+ modelbuilder.error(nsig.n_type, "Redef Error: `{mpropdef.mproperty}` is a procedure, not a function.")
mpropdef.msignature = null
mpropdef.is_broken = true
return
# For parameters, type is always useless in a redef.
# For return type, type is useless if not covariant with introduction.
redef fun check_repeated_types(modelbuilder) do
+ var mpropdef = self.mpropdef
+ if mpropdef == null then return
if mpropdef.is_intro or n_signature == null then return
# check params
for param in n_signature.n_params do
# Type is useless if the attribute type is the same thant the intro.
redef fun check_repeated_types(modelbuilder) do
+ var mreadpropdef = self.mreadpropdef
+ if mreadpropdef == null then return
if mreadpropdef.is_intro or n_type == null then return
# get intro
var intro = mreadpropdef.mproperty.intro