Merge: Less null warnings in src/
authorJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 18:15:12 +0000 (14:15 -0400)
committerJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 18:15:12 +0000 (14:15 -0400)
Some small warning reductions while wandering in the source code of src/

Pull-Request: #1782
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

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

index 560dc60..c6cdb26 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 49671f9..273d645 100644 (file)
@@ -246,7 +246,6 @@ class GlobalCompiler
                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
index 9e9e94f..dc911fd 100644 (file)
@@ -157,7 +157,7 @@ class NaiveInterpreter
                        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
@@ -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
@@ -566,6 +566,7 @@ class NaiveInterpreter
        # 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
index fdfe399..6aa937e 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..3841daf 100644 (file)
@@ -283,6 +283,7 @@ redef class MModule
                        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}:"
@@ -1566,6 +1567,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 d516da7..06f2fb6 100644 (file)
@@ -27,7 +27,7 @@ class MPackageTree
 
        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
@@ -85,7 +85,7 @@ private class LinexComparator
                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
@@ -165,7 +165,7 @@ class MPackageDot
                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
index 4624314..0161ad0 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
@@ -1540,6 +1546,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