diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 2d45de8e..1806e344 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -3347,12 +3347,9 @@ static int reparse_new_decl(declinfo_t *decl, int flags) if (matchtoken('[')) parse_old_array_dims(decl, flags); } else { - // No post-dimensions means anything here is part of the type. if (matchtoken('[')) { - if (decl->type.numdim > 0) { - if (lexpeek('[')) + if (decl->type.numdim > 0) error(121); - } parse_old_array_dims(decl, flags); } else if (decl->type.numdim) { // Reset dimension sizes. diff --git a/sourcepawn/compiler/tests/fail-newdecls.sp b/sourcepawn/compiler/tests/fail-newdecls.sp new file mode 100644 index 00000000..197c4b10 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-newdecls.sp @@ -0,0 +1,13 @@ +native int[] egg6(); +forward float[] egg7(); +new void crab4; +int[] yam1 = {1,2,3}, yam2[] = {3,4,5}; + +forward void OnPluginStart(); + +public int OnPluginStart() +{ + +} + + diff --git a/sourcepawn/compiler/tests/fail-newdecls.txt b/sourcepawn/compiler/tests/fail-newdecls.txt new file mode 100644 index 00000000..4258d3f8 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-newdecls.txt @@ -0,0 +1,5 @@ +(1) : error 141: natives, forwards, and public functions cannot return arrays +(2) : error 141: natives, forwards, and public functions cannot return arrays +(3) : error 143: new-style declarations should not have "new" +(4) : error 121: cannot specify array dimensions on both type and name +(6) : error 025: function heading differs from prototype diff --git a/sourcepawn/compiler/tests/ok-newdecls.sp b/sourcepawn/compiler/tests/ok-newdecls.sp new file mode 100644 index 00000000..33000f14 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-newdecls.sp @@ -0,0 +1,55 @@ +native egg(); +native void egg2(); +native int egg3(); +native bool egg4(); +native bool:egg5(); + +new crab; +new crab2 = 5; +bool crab3 = true; +int crab4 = 6; +new crab5[] = {1, 2, 3}; +bool[] crab6 = {true, false, false, true} +bool crab7[] = {false, true, true} +char crab8[] = "hello" +char[] crab9 = "bye" + +native float operator*(float oper1, float oper2) = FloatMul; + +forward void OnPluginStart(); + +public int Crab() +{ +} + +public float Crab2() +{ +} + +public Crab3() +{ +} + +stock char[] Crab4() +{ + new String:t[5] = "egg"; + return t; +} + +new yam, yam2, yam3 +new Float:ham, bool:ham2; +int cram, cram2, cram3; +new cram4[] = {1, 2}, cram5[] = {3, 4, 7} +int cram6[] = {1, 2}, cram7[] = {3, 4, 7} +int[] cram8 = {3, 4}, cram9 = {4, 8, 10} + +public OnPluginStart() +{ + new String:t[5]; + t = Crab4(); + cram4[0] = 2 + cram5[2] = 2 + cram7[2] = 2 + cram8[1] = 5 + cram9[2] = 5 +}