src: remove some `call on nullable` warning with a non-null local variable
authorJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 00:30:33 +0000 (20:30 -0400)
committerJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 00:30:33 +0000 (20:30 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit
src/interpreter/naive_interpreter.nit
src/model/mmodule.nit
src/model/model.nit
src/modelize/modelize_property.nit

index 55b644f..aa24185 100644 (file)
@@ -2074,6 +2074,8 @@ redef class MMethodDef
        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
@@ -2083,11 +2085,11 @@ redef class MMethodDef
                        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
@@ -3696,7 +3698,8 @@ 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
@@ -3707,7 +3710,7 @@ redef class ASuperExpr
                                # 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)
@@ -3722,7 +3725,7 @@ redef class ASuperExpr
 
                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
index f2aabe4..82800cf 100644 (file)
@@ -526,7 +526,7 @@ class NaiveInterpreter
        # 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
index db4b8c6..c637c41 100644 (file)
@@ -65,6 +65,7 @@ redef class MGroup
        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
@@ -164,6 +165,7 @@ class MModule
        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
index 941bae7..820b306 100644 (file)
@@ -1566,6 +1566,7 @@ class MParameterType
                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
index 25502fd..ef9ef0b 100644 (file)
@@ -181,8 +181,9 @@ redef class ModelBuilder
                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
@@ -190,12 +191,14 @@ redef class ModelBuilder
                                        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
@@ -207,7 +210,7 @@ redef class ModelBuilder
                                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)
@@ -224,6 +227,7 @@ redef class ModelBuilder
                        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
@@ -349,7 +353,7 @@ redef class ModelBuilder
                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)
@@ -1025,7 +1029,7 @@ redef class AMethPropdef
                        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
@@ -1074,6 +1078,8 @@ redef class AMethPropdef
        # 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
@@ -1538,6 +1544,8 @@ redef class AAttrPropdef
 
        # 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