From b6eb3b041bf074d142d991455ceeed76b669d5e0 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Jun 2014 13:28:35 -0700 Subject: [PATCH] Fix bug in requiring braces for new methods. --- sourcepawn/compiler/sc.h | 1 - sourcepawn/compiler/sc1.c | 4 +++- sourcepawn/compiler/tests/fail-method-requires-brace.sp | 8 ++++++++ sourcepawn/compiler/tests/fail-method-requires-brace.txt | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 sourcepawn/compiler/tests/fail-method-requires-brace.sp create mode 100644 sourcepawn/compiler/tests/fail-method-requires-brace.txt diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index 8502b633..48859abc 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -235,7 +235,6 @@ typedef struct s_symbol { #define sGLOBAL 0 /* global variable/constant class (no states) */ #define sLOCAL 1 /* local variable/constant */ #define sSTATIC 2 /* global life, local scope */ -#define sPROXY 3 /* only find proxies */ #define sSTATEVAR 3 /* criterion to find variables (sSTATEVAR implies a global variable) */ diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 415e8fbc..3b6efe69 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -82,6 +82,7 @@ typedef struct funcstub_setup_s { const char *name; int return_tag; int this_tag; + int is_new; } funcstub_setup_t; static void resetglobals(void); @@ -3559,6 +3560,7 @@ methodmap_method_t *parse_method(methodmap_t *map) check_name_length(fullname); setup.name = fullname; + setup.is_new = TRUE; if (is_native) { target = funcstub(TRUE, &setup); @@ -4927,7 +4929,7 @@ static int newfunc(const funcstub_setup_t *setup,int fpublic,int fstatic,int sto lexpush(); } else { // We require '{' for new methods. - if (setup->this_tag != -1) + if (setup->is_new) needtoken('{'); /* Insert a separator so that comments following the statement will not diff --git a/sourcepawn/compiler/tests/fail-method-requires-brace.sp b/sourcepawn/compiler/tests/fail-method-requires-brace.sp new file mode 100644 index 00000000..c5f05f8e --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-requires-brace.sp @@ -0,0 +1,8 @@ +methodmap Crab { + public Crab() return Crab:5; +}; + +public main() { + new Crab:crab = Crab(); + return _:crab; +} diff --git a/sourcepawn/compiler/tests/fail-method-requires-brace.txt b/sourcepawn/compiler/tests/fail-method-requires-brace.txt new file mode 100644 index 00000000..986fc3b9 --- /dev/null +++ b/sourcepawn/compiler/tests/fail-method-requires-brace.txt @@ -0,0 +1 @@ +expected token: "{", but found "return"