typing: use `location` attribute instead of `node` to isolate CallSite from the AST
[nit.git] / src / semantize / auto_super_init.nit
index b16eaf5..1da19d4 100644 (file)
@@ -56,8 +56,10 @@ redef class AMethPropdef
        # Collect initializers and build the auto-init
        fun do_auto_super_init(modelbuilder: ModelBuilder)
        do
-               var mclassdef = self.parent.as(AClassdef).mclassdef.as(not null)
-               var mpropdef = self.mpropdef.as(not null)
+               var mclassdef = self.parent.as(AClassdef).mclassdef
+               if mclassdef == null then return # skip error
+               var mpropdef = self.mpropdef
+               if mpropdef == null then return # skip error
                var mmodule = mpropdef.mclassdef.mmodule
                var anchor = mclassdef.bound_mtype
                var recvtype = mclassdef.mclass.mclass_type
@@ -67,20 +69,10 @@ redef class AMethPropdef
 
                # Collect only for constructors
                if not mpropdef.mproperty.is_init or mpropdef.mproperty.is_new then
-                       if nosuper != null then modelbuilder.error(nosuper, "Error: nosuper only in `init`")
+                       if nosuper != null then modelbuilder.error(nosuper, "Error: `nosuper` only allowed in `init`.")
                        return
                end
 
-               # FIXME: THIS IS STUPID (be here to keep the old code working)
-               if not mpropdef.mclassdef.is_intro then return
-
-               # Do we inherit for a constructor?
-               var skip = true
-               for cd in mclassdef.in_hierarchy.direct_greaters do
-                       if cd.mclass.kind.need_init then skip = false
-               end
-               if skip then return
-
                # Now we search for the absence of any explicit super-init invocation
                #  * via a "super"
                #  * via a call of an other init
@@ -90,7 +82,7 @@ redef class AMethPropdef
                        v.enter_visit(nblock)
                        var anode = v.has_explicit_super_init
                        if anode != null then
-                               if nosuper != null then modelbuilder.error(anode, "Error: method is annotated nosuper but a constructor call is present")
+                               if nosuper != null then modelbuilder.error(anode, "Error: method is annotated `nosuper` but a super-constructor call is present.")
                                return
                        end
                        if v.is_broken then return # skip
@@ -102,6 +94,7 @@ redef class AMethPropdef
                if not mpropdef.is_intro then
                        auto_super_call = true
                        mpropdef.has_supercall = true
+                       modelbuilder.toolcontext.info("Auto-super call for {mpropdef}", 4)
                        return
                end
 
@@ -119,7 +112,7 @@ redef class AMethPropdef
                                candidate = modelbuilder.try_get_mproperty_by_name2(self, mmodule, msupertype, "init")
                        end
                        if candidate == null then
-                               modelbuilder.error(self, "Error: Cannot do an implicit constructor call in {mpropdef}; there is no constructor named {mpropdef.mproperty.name} in {msupertype}.")
+                               modelbuilder.error(self, "Error: cannot do an implicit constructor call in `{mpropdef}`; there is no constructor named `{mpropdef.mproperty.name}` in `{msupertype}`.")
                                return
                        end
                        assert candidate isa MMethod
@@ -134,8 +127,9 @@ redef class AMethPropdef
                        var msignature = candidatedef.new_msignature or else candidatedef.msignature
                        msignature = msignature.resolve_for(recvtype, anchor, mmodule, true)
 
-                       var callsite = new CallSite(self, recvtype, mmodule, anchor, true, candidate, candidatedef, msignature, false)
+                       var callsite = new CallSite(hot_location, recvtype, mmodule, anchor, true, candidate, candidatedef, msignature, false)
                        auto_super_inits.add(callsite)
+                       modelbuilder.toolcontext.info("Old-style auto-super init for {mpropdef} to {candidate.full_name}", 4)
                end
 
                # No old style? The look for new-style super constructors (called from a old style constructor)
@@ -157,7 +151,7 @@ redef class AMethPropdef
                                        var i = 0
                                        for p in spd.initializers do
                                                if p != candidatedef.initializers[i] then
-                                                       modelbuilder.error(self, "Error: Cannot do an implicit constructor call to comflicting for inherited inits {spd}({spd.initializers.join(", ")}) and {candidatedef}({candidatedef.initializers.join(", ")}). NOTE: Do not mix old-style and new-style init!")
+                                                       modelbuilder.error(self, "Error: cannot do an implicit constructor call to conflicting inherited inits `{spd}({spd.initializers.join(", ")}`) and `{candidatedef}({candidatedef.initializers.join(", ")}`). NOTE: Do not mix old-style and new-style init!")
                                                        return
                                                end
                                                i += 1
@@ -168,11 +162,12 @@ redef class AMethPropdef
                        var msignature = candidatedef.new_msignature or else candidatedef.msignature
                        msignature = msignature.resolve_for(recvtype, anchor, mmodule, true)
 
-                       var callsite = new CallSite(self, recvtype, mmodule, anchor, true, the_root_init_mmethod, candidatedef, msignature, false)
+                       var callsite = new CallSite(hot_location, recvtype, mmodule, anchor, true, the_root_init_mmethod, candidatedef, msignature, false)
                        auto_super_inits.add(callsite)
+                       modelbuilder.toolcontext.info("Auto-super init for {mpropdef} to {the_root_init_mmethod.full_name}", 4)
                end
                if auto_super_inits.is_empty then
-                       modelbuilder.error(self, "Error: No constructors to call implicitely in {mpropdef}. Call one explicitely.")
+                       modelbuilder.error(self, "Error: no constructors to call implicitly in `{mpropdef}`. Call one explicitly.")
                        return
                end
 
@@ -182,7 +177,7 @@ redef class AMethPropdef
                        var msig = mpropdef.msignature.as(not null)
                        var supermsig = auto_super_init.msignature
                        if supermsig.arity > msig.arity then
-                               modelbuilder.error(self, "Error: Cannot do an implicit constructor call to {auto_super_init_def}{supermsig}. Expected at least {supermsig.arity} arguments, got {msig.arity}.")
+                               modelbuilder.error(self, "Error: cannot do an implicit constructor call to `{auto_super_init_def}{supermsig}`. Expected at least `{supermsig.arity}` arguments, got `{msig.arity}`.")
                                continue
                        end
                        var i = 0
@@ -191,7 +186,7 @@ redef class AMethPropdef
                                var sub = p.mtype
                                var sup = sp.mtype
                                if not sub.is_subtype(mmodule, anchor, sup) then
-                                       modelbuilder.error(self, "Error: Cannot do an implicit constructor call to {auto_super_init_def}{supermsig}. Expected argument #{i} of type {sp.mtype}, got implicit argument {p.name} of type {p.mtype}.")
+                                       modelbuilder.error(self, "Error: cannot do an implicit constructor call to `{auto_super_init_def}{supermsig}`. Expected argument #{i} of type `{sp.mtype}`, got implicit argument `{p.name}` of type `{p.mtype}`.")
                                        break
                                end
                                i += 1