From a15153e9b82403f7d56155def1bec3753fc3ec63 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 3 Jul 2014 00:21:18 -0700 Subject: [PATCH] Improve error messaging. --- sourcepawn/compiler/sc1.c | 4 +++- sourcepawn/compiler/sc5.scp | 1 + sourcepawn/compiler/tests/fail-bad-arg-decls.sp | 15 +++++++++++++++ sourcepawn/compiler/tests/fail-bad-arg-decls.txt | 3 +++ sourcepawn/compiler/tests/ok-new-decl-args.sp | 8 +++++++- 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 sourcepawn/compiler/tests/fail-bad-arg-decls.sp create mode 100644 sourcepawn/compiler/tests/fail-bad-arg-decls.txt diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 464d9546..0156b1f6 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -3341,8 +3341,10 @@ static int parse_new_typeexpr(typeinfo_t *type, const token_t *first, int flags) break; } type->dim[type->numdim++] = 0; - if (!needtoken(']')) + if (!matchtoken(']')) { + error(140); goto err_out; + } } while (matchtoken('[')); type->ident = iARRAY; } diff --git a/sourcepawn/compiler/sc5.scp b/sourcepawn/compiler/sc5.scp index 37f37def..ab2cf3ae 100644 --- a/sourcepawn/compiler/sc5.scp +++ b/sourcepawn/compiler/sc5.scp @@ -183,6 +183,7 @@ static char *errmsg[] = { /*137*/ "cannot mix reference and array types\n", /*138*/ "const was specified twice\n", /*139*/ "could not find type \"%s\"\n", +/*140*/ "new-style array types cannot specify dimension sizes as part of their type\n", #else "\250\264\307\231\271k\214:\234\317bu\201fo\223\204\220\012", "\202l\224\252s\205g\370\346e\233\201(\242\250\324\273\202) \256 f\247low ea\274 \042c\342e\042\012", diff --git a/sourcepawn/compiler/tests/fail-bad-arg-decls.sp b/sourcepawn/compiler/tests/fail-bad-arg-decls.sp new file mode 100644 index 00000000..cda0ec89 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-bad-arg-decls.sp @@ -0,0 +1,15 @@ +stock A(int) +{ +} + +stock B(int[5] N) +{ +} + +stock C(int:N) +{ +} + +public main() +{ +} diff --git a/sourcepawn/compiler/tests/fail-bad-arg-decls.txt b/sourcepawn/compiler/tests/fail-bad-arg-decls.txt new file mode 100644 index 00000000..d92248fe --- /dev/null +++ b/sourcepawn/compiler/tests/fail-bad-arg-decls.txt @@ -0,0 +1,3 @@ +(1) : error 001: expected token: "-identifier-", but found ")" +(5) : error 140: new-style array types cannot specify dimension sizes as part of their type +(9) : error 001: expected token: "-identifier-", but found ":" diff --git a/sourcepawn/compiler/tests/ok-new-decl-args.sp b/sourcepawn/compiler/tests/ok-new-decl-args.sp index d938312b..75fe92f7 100644 --- a/sourcepawn/compiler/tests/ok-new-decl-args.sp +++ b/sourcepawn/compiler/tests/ok-new-decl-args.sp @@ -23,16 +23,22 @@ stock E(E2 t) { } -stock F(int n[10]) { +stock F(const int n[10]) { +} + +stock G(int& n) +{ } public main() { new x[10] + new t A(1) B(x) C(x) D(E1:5) E(E2:5) F(x) + G(t) }