Merge: Correct warn on noautoinit
authorJean Privat <jean@pryen.org>
Thu, 28 May 2015 00:19:25 +0000 (20:19 -0400)
committerJean Privat <jean@pryen.org>
Thu, 28 May 2015 00:19:25 +0000 (20:19 -0400)
Move the analysis of the class annotation `noautoinit` after the inheritance of initializers so the warning is correct, thus fixes #1350

The main commit is mainly moving the code in the same method.

Pull-Request: #1408
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>

src/modelize/modelize_property.nit
tests/base_init_autoinit3.nit
tests/sav/base_init_autoinit3_alt9.res [new file with mode: 0644]

index 66d5e9f..5242cdc 100644 (file)
@@ -299,25 +299,19 @@ redef class ModelBuilder
                                        abort
                                end
                        end
-               else if noautoinit != null then
-                       if initializers.is_empty then
-                               warning(noautoinit, "useless-noautoinit", "Warning: the list of autoinit is already empty.")
-                       end
-                       # Just clear initializers
-                       mparameters.clear
-                       initializers.clear
                else
                        # Search the longest-one and checks for conflict
                        var longest = spropdefs.first
                        if spropdefs.length > 1 then
-                               # Check for conflict in the order of initializers
-                               # Each initializer list must me a prefix of the longest list
                                # part 1. find the longest list
                                for spd in spropdefs do
                                        if spd.initializers.length > longest.initializers.length then longest = spd
                                end
                                # part 2. compare
-                               for spd in spropdefs do
+                               # Check for conflict in the order of initializers
+                               # Each initializer list must me a prefix of the longest list
+                               # If `noautoinit` is set, just ignore conflicts
+                               if noautoinit == null then for spd in spropdefs do
                                        var i = 0
                                        for p in spd.initializers do
                                                if p != longest.initializers[i] then
@@ -330,17 +324,27 @@ redef class ModelBuilder
                                end
                        end
 
-                       # Can we just inherit?
-                       if spropdefs.length == 1 and mparameters.is_empty and defined_init == null then
-                               self.toolcontext.info("{mclassdef} inherits the basic constructor {longest}", 3)
-                               mclassdef.mclass.root_init = longest
-                               return
-                       end
+                       if noautoinit != null then
+                               # If there is local or inherited initializers, then complain.
+                               if initializers.is_empty and longest.initializers.is_empty then
+                                       warning(noautoinit, "useless-noautoinit", "Warning: the list of autoinit is already empty.")
+                               end
+                               # Just clear initializers
+                               mparameters.clear
+                               initializers.clear
+                       else
+                               # Can we just inherit?
+                               if spropdefs.length == 1 and mparameters.is_empty and defined_init == null then
+                                       self.toolcontext.info("{mclassdef} inherits the basic constructor {longest}", 3)
+                                       mclassdef.mclass.root_init = longest
+                                       return
+                               end
 
-                       # Combine the inherited list to what is collected
-                       if longest.initializers.length > 0 then
-                               mparameters.prepend longest.new_msignature.mparameters
-                               initializers.prepend longest.initializers
+                               # Combine the inherited list to what is collected
+                               if longest.initializers.length > 0 then
+                                       mparameters.prepend longest.new_msignature.mparameters
+                                       initializers.prepend longest.initializers
+                               end
                        end
                end
 
index 37c2cb2..51cb465 100644 (file)
@@ -40,7 +40,7 @@ class E
        noautoinit #alt6#
        #alt6,7# autoinit
        super A
-       var a: A
+       var a: A #alt9#
 end
 
 class F
diff --git a/tests/sav/base_init_autoinit3_alt9.res b/tests/sav/base_init_autoinit3_alt9.res
new file mode 100644 (file)
index 0000000..6851c6d
--- /dev/null
@@ -0,0 +1,8 @@
+1
+2
+false
+3
+3.300000
+4
+true
+4.400000