Merge: modelize: ask that attributes in refinements are either noautoninit or have...
authorJean Privat <jean@pryen.org>
Sat, 30 May 2015 00:37:16 +0000 (20:37 -0400)
committerJean Privat <jean@pryen.org>
Sat, 30 May 2015 00:37:16 +0000 (20:37 -0400)
Without value, attributes in introductions does not have the same semantic that attributes in refinements

In introduction attributes are implicitly `autoinit`, in refinements they are `noautoinit`.

This is not POLA since

* this confuse beginners
* readers have to remember if they are in an intro or a refinement
* aditionnal cognitive fragility in constructors (more cases and rules to take in account)

This PR make `autoinit` the default and ask that attributes declared in refinement are either annotated `noautoinit` or have a default value.
This way, the writer has to think about the implication of adding a new attributes in existing classes, especially to think about their initialization. Thus this could help the programmer to avoid bad error.

For the moment, I just display a warning because I want to wait for feedback before doing a big migration (or doing nothing if people hate that), I also want to use jenkins to count and locate these new warnings.

Related to #1322

Pull-Request: #1411
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/standard/string.nit
src/modelize/modelize_property.nit

index b02ff9b..7fe5de3 100644 (file)
@@ -2476,7 +2476,7 @@ extern class NativeString `{ char* `}
 end
 
 redef class Sys
-       private var args_cache: nullable Sequence[String]
+       private var args_cache: nullable Sequence[String] = null
 
        # The arguments of the program as given by the OS
        fun program_args: Sequence[String]
index 0a948d2..91c552f 100644 (file)
@@ -1245,6 +1245,10 @@ redef class AAttrPropdef
                        return
                end
 
+               if not mclassdef.is_intro and not has_value and not noinit then
+                       modelbuilder.advice(self, "attr-in-refinement", "Warning: attributes in refinement need a value or `noautoinit`.")
+               end
+
                var writename = name + "="
                var atwritable = self.get_single_annotation("writable", modelbuilder)
                if atwritable != null then