various phases: more robust for keep-going
[nit.git] / src / semantize / auto_super_init.nit
index 31a508a..07b4f46 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Computing of super-constructors that must be implicitely called at the begin of constructors.
+# Computing of super-constructors that must be implicitly called at the begin of constructors.
 # The current rules are a bit crazy but whatever.
 module auto_super_init
 
@@ -22,6 +22,7 @@ import typing
 private import annotation
 
 redef class ToolContext
+       # Phase that inject `super` in constructors that need it.
        var auto_super_init_phase: Phase = new AutoSuperInitPhase(self, [typing_phase])
 end
 
@@ -55,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
@@ -65,14 +68,11 @@ redef class AMethPropdef
                var nosuper = get_single_annotation("nosuper", modelbuilder)
 
                # Collect only for constructors
-               if not mpropdef.mproperty.is_init then
+               if not mpropdef.mproperty.is_init or mpropdef.mproperty.is_new then
                        if nosuper != null then modelbuilder.error(nosuper, "Error: nosuper only 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
@@ -101,6 +101,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
 
@@ -135,6 +136,7 @@ redef class AMethPropdef
 
                        var callsite = new CallSite(self, 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)
@@ -169,6 +171,7 @@ redef class AMethPropdef
 
                        var callsite = new CallSite(self, 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.")