From 1a83ca57fca260747295e53e4fcf5bb2e5e4bc59 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 12 Jul 2014 10:05:43 -0700 Subject: [PATCH] Allow chaining off method calls. (bug 6178) --- sourcepawn/compiler/sc3.c | 5 ++++ sourcepawn/compiler/tests/ok-chaining.sp | 38 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 sourcepawn/compiler/tests/ok-chaining.sp diff --git a/sourcepawn/compiler/sc3.c b/sourcepawn/compiler/sc3.c index 13348bfd..bf2d630c 100644 --- a/sourcepawn/compiler/sc3.c +++ b/sourcepawn/compiler/sc3.c @@ -2250,12 +2250,17 @@ restart: error(4,symname); /* function not defined */ } /* if */ callfunction(sym,implicitthis,lval1,TRUE); + if (lexpeek('.')) { + lvalue = FALSE; + goto restart; + } return FALSE; /* result of function call is no lvalue */ } /* if */ } /* if */ if (sym!=NULL && lval1->ident==iFUNCTN) { assert(sym->ident==iFUNCTN); if (sc_allowproccall) { + // Note: this is unreachable in SourceMod, we don't support paren-less calls. callfunction(sym,NULL,lval1,FALSE); } else if ((sym->usage & uNATIVE) != uNATIVE) { symbol *oldsym=sym; diff --git a/sourcepawn/compiler/tests/ok-chaining.sp b/sourcepawn/compiler/tests/ok-chaining.sp new file mode 100644 index 00000000..3a8849d2 --- /dev/null +++ b/sourcepawn/compiler/tests/ok-chaining.sp @@ -0,0 +1,38 @@ +methodmap Duck +{ + property bool MyProp + { + public get() { + return true; + } + } +}; + +public bool OnPluginStart() +{ + Duck duck = GiveMeADuck(); + + // no compile errors or warnings + if (duck.MyProp) + { + } + + // error 001: expected token: ")", but found "." + // error 029: invalid expression, assumed zero + // error 017: undefined symbol "MyProp" + if (GiveMeADuck().MyProp) + { + } + + // warning 213: tag mismatch + // error 001: expected token: ";", but found "." + // error 029: invalid expression, assumed zero + // error 017: undefined symbol "MyProp" + bool prop = GiveMeADuck().MyProp; + return prop +} + +stock Duck GiveMeADuck() +{ + return Duck:1; +}