From: Jean Privat Date: Fri, 20 Jan 2012 01:22:10 +0000 (-0500) Subject: syntax: use attributes names for parameters in implicit inits X-Git-Tag: v0.5~32^2~31 X-Git-Url: http://nitlanguage.org syntax: use attributes names for parameters in implicit inits 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 --- diff --git a/src/syntax/mmbuilder.nit b/src/syntax/mmbuilder.nit index 510f0fc..0934d7f 100644 --- a/src/syntax/mmbuilder.nit +++ b/src/syntax/mmbuilder.nit @@ -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 diff --git a/tests/sav/error_init_auto.sav b/tests/sav/error_init_auto.sav index 5f13350..5e15069 100644 --- a/tests/sav/error_init_auto.sav +++ b/tests/sav/error_init_auto.sav @@ -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. diff --git a/tests/sav/error_init_auto_alt2.sav b/tests/sav/error_init_auto_alt2.sav index 113433e..3fdbc48 100644 --- a/tests/sav/error_init_auto_alt2.sav +++ b/tests/sav/error_init_auto_alt2.sav @@ -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.