syntax: use attributes names for parameters in implicit inits
authorJean Privat <jean@pryen.org>
Fri, 20 Jan 2012 01:22:10 +0000 (20:22 -0500)
committerJean Privat <jean@pryen.org>
Fri, 3 Feb 2012 16:11:40 +0000 (11:11 -0500)
Use the name of the attributes as the name of the parameters for the
implicit inits.
Also take care of removing the first '_' (old style) or '@' (new style)
used to name attributes.

Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/mmbuilder.nit
tests/sav/error_init_auto.sav
tests/sav/error_init_auto_alt2.sav

index 510f0fc..0934d7f 100644 (file)
@@ -302,7 +302,11 @@ redef class MMImplicitInit
                for a in unassigned_attributes do
                        var sig = a.signature
                        if sig == null then return # Broken attribute definition
-                       params.add( new MMParam( sig.return_type.as(not null), once "recv".to_symbol))
+                       var name = a.name
+                       if name.to_s.first == '_' or name.to_s.first == '@' then
+                               name = a.to_s.substring_from(1).to_symbol
+                       end
+                       params.add(new MMParam(sig.return_type.as(not null), name))
                end
                signature = new MMSignature(params, null, local_class.get_type)
        end
index 5f13350..5e15069 100644 (file)
@@ -1,4 +1,4 @@
-./error_init_auto.nit:34,5--9: Error: arity mismatch; prototype is 'init(recv: Int)'.
-./error_init_auto.nit:36,5--14: Error: arity mismatch; prototype is 'init(recv: Int)'.
-./error_init_auto.nit:37,5--17: Error: arity mismatch; prototype is 'init(recv: Int)'.
+./error_init_auto.nit:34,5--9: Error: arity mismatch; prototype is 'init(x: Int)'.
+./error_init_auto.nit:36,5--14: Error: arity mismatch; prototype is 'init(x: Int)'.
+./error_init_auto.nit:37,5--17: Error: arity mismatch; prototype is 'init(x: Int)'.
 ./error_init_auto.nit:38,5--15: Error: Method 'foo' doesn't exists in A.
index 113433e..3fdbc48 100644 (file)
@@ -1,4 +1,4 @@
-alt/error_init_auto_alt2.nit:33,5--9: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
-alt/error_init_auto_alt2.nit:34,5--11: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
-alt/error_init_auto_alt2.nit:36,5--17: Error: arity mismatch; prototype is 'init(recv: Int, recv: Int)'.
+alt/error_init_auto_alt2.nit:33,5--9: Error: arity mismatch; prototype is 'init(x: Int, y: Int)'.
+alt/error_init_auto_alt2.nit:34,5--11: Error: arity mismatch; prototype is 'init(x: Int, y: Int)'.
+alt/error_init_auto_alt2.nit:36,5--17: Error: arity mismatch; prototype is 'init(x: Int, y: Int)'.
 alt/error_init_auto_alt2.nit:37,5--15: Error: Method 'foo' doesn't exists in A.