From 704e9579f785a42c3950f911b7ee16a4c1916b5e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 8 Nov 2014 20:27:39 -0800 Subject: [PATCH] Fix comparisons of derived tags (bug 6239). --- sourcepawn/compiler/sc.h | 1 + sourcepawn/compiler/sc3.cpp | 4 ++-- .../compiler/tests/ok-coerce-on-operators.sp | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 sourcepawn/compiler/tests/ok-coerce-on-operators.sp diff --git a/sourcepawn/compiler/sc.h b/sourcepawn/compiler/sc.h index b46a6baa..5b611599 100644 --- a/sourcepawn/compiler/sc.h +++ b/sourcepawn/compiler/sc.h @@ -647,6 +647,7 @@ char *itoh(ucell val); #define MATCHTAG_COERCE 0x1 // allow coercion #define MATCHTAG_SILENT 0x2 // silence the error(213) warning #define MATCHTAG_COMMUTATIVE 0x4 // order does not matter +#define MATCHTAG_DEDUCE 0x8 // correct coercion /* function prototypes in SC3.C */ int check_userop(void (*oper)(void),int tag1,int tag2,int numparam, diff --git a/sourcepawn/compiler/sc3.cpp b/sourcepawn/compiler/sc3.cpp index c8584e87..1d70fe67 100644 --- a/sourcepawn/compiler/sc3.cpp +++ b/sourcepawn/compiler/sc3.cpp @@ -550,7 +550,7 @@ int matchtag(int formaltag, int actualtag, int flags) return TRUE; } - if (flags & MATCHTAG_COERCE) { + if (flags & (MATCHTAG_COERCE|MATCHTAG_DEDUCE)) { // See if the tag has a methodmap associated with it. If so, see if the given // tag is anywhere on the inheritance chain. methodmap_t *map = methodmap_find_by_tag(actualtag); @@ -888,7 +888,7 @@ static void plnge2(void (*oper)(void), } else { // For the purposes of tag matching, we consider the order to be irrelevant. if (!checktag_string(lval1, lval2)) - matchtag(lval1->tag, lval2->tag, MATCHTAG_COMMUTATIVE); + matchtag(lval1->tag, lval2->tag, MATCHTAG_COMMUTATIVE|MATCHTAG_DEDUCE); (*oper)(); /* do the (signed) operation */ lval1->ident=iEXPRESSION; } /* if */ diff --git a/sourcepawn/compiler/tests/ok-coerce-on-operators.sp b/sourcepawn/compiler/tests/ok-coerce-on-operators.sp new file mode 100644 index 00000000..643124dd --- /dev/null +++ b/sourcepawn/compiler/tests/ok-coerce-on-operators.sp @@ -0,0 +1,18 @@ +enum Handle { + INVALID_HANDLE, +}; + +methodmap Handle {}; +methodmap ArrayList < Handle {}; + +public void MyCommand() +{ + ArrayList myList; + if (INVALID_HANDLE == myList) + { + } + if (myList == INVALID_HANDLE) + { + } +} +