Skip to content

tag mismatch #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Daniel-Cortez opened this issue Apr 16, 2020 · 4 comments
Closed

tag mismatch #514

Daniel-Cortez opened this issue Apr 16, 2020 · 4 comments

Comments

@Daniel-Cortez
Copy link
Contributor

Daniel-Cortez commented Apr 16, 2020

Issue description:

Assigning a tagged value to an array cell indexed with an enum constant makes the compiler print warning 213 (tag mismatch), even though the array has the same tag.

Minimal complete verifiable example (MCVE):

#include <a_samp>

const TD_0 = 0;
enum { TD_1 = 1 };
new Text:textdraws[2];

main()
{
    // no warnings/errors on the following line, as `TD_0`
    // is a regular constant, not an enum element
    textdraws[TD_0] = TextDrawCreate(0.0, 0.0, "-");

    // warning 213: tag mismatch: expected tag none ("_"), but found "Text"
    textdraws[TD_1] = TextDrawCreate(0.0, 0.0, "-");
}

It seems that if an array is indexed with an enum constant, the tag of the said constant somehow overrides the array tag, so in the above example the compiler expects no tag (_:) instead of Text:, which doesn't seem to be correct.

Originally reported by the forum user 'tnc' here: https://pro-pawn.ru/showthread.php?2207-Pawn-compiler-%283-10%29&p=96537&viewfull=1#post96537

Workspace Information:

  • Compiler version: 3.2.3664, 3.10.1 - 3.10.10
  • Command line arguments provided (or sampctl version):
  • Operating System:
@Daniel-Cortez
Copy link
Contributor Author

Daniel-Cortez commented Apr 16, 2020

I think I've tracked down the code that overrides the tag:

compiler/source/compiler/sc3.c

Lines 1783 to 1786 in ec5b746

if (lval2.sym!=NULL && lval2.sym->dim.array.length>0 && sym->dim.array.level==0) {
lval1->tag=lval2.sym->x.tags.index;
lval1->constval=lval2.sym->dim.array.length;
} /* if */

According to a comment before that code, it's meant exactly for the cases when the array is indexed by an enum element, e.g.:

enum ePlayerInfo
{
    Float:pHealth
};
new player_info[MAX_PLAYERS][ePlayerInfo];
// ...
// `player_info` has tag `_:` (no tag), but the resulting tag
// is overridden with the tag from `pHealth`
player_info[playerid][pHealth] = 100.0;

which makes sense, but should this rule really apply to all enum elements, including the ones that belong to anonymous enumerations?
@Y-Less ?

Fixing this should be trivial, we only need to add an extra check lval2.sym->parent!=NULL to make the compiler override the resulting tag only if the enum element belongs to a named enum.

@Y-Less
Copy link
Member

Y-Less commented Apr 17, 2020

Is this related to #444 or #454? That would explain where the bug came from since 3664.

@Y-Less
Copy link
Member

Y-Less commented Apr 17, 2020

But you're right, anonymous enums probably shouldn't apply themselves as they weren't used to declare the original array. I can only think of very obtuse and probably wrong code that would be affected by this, and I wouldn't be against just telling people to change that code.

@Daniel-Cortez
Copy link
Contributor Author

Is this related to #444 or #454? That would explain where the bug came from since 3664.

No, #444 was a completely different bug (an oversight in the parsing code that made the compiler silently ignore tags in anonymous enum declarations).

However, I just re-tested the stock 3.2.3664 compiler for this bug and it seems that that release is affected as well (which is strange, because I'm pretty sure there was no warning when I tested 3664 for this bug the first time).

Daniel-Cortez added a commit to Daniel-Cortez/pawn-3.10 that referenced this issue May 5, 2020
Daniel-Cortez added a commit to Daniel-Cortez/pawn-3.10 that referenced this issue Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants