Skip to content

#emit stuck in previous block #319

Open
@Y-Less

Description

@Y-Less

Is this a BUG REPORT, FEATURE REQUEST or QUESTION?:

  • Bug Report
  • Feature Request
  • Question

What happened:

new a;
if (FALSE)
    printf("hi");
#emit CONST.pri 42
#emit STOR.S.pri a
printf("%d", a);

Prints 0.

What you expected to happen:

Print 42.

How to reproduce it (as minimally and precisely as possible):

^

Anything else we need to know?:

The #emit code isn't properly scoped, so compiles as:

new a;
if (FALSE)
{
    printf("hi");
    #emit CONST.pri 42
    #emit STOR.S.pri a
}
printf("%d", a);

I didn't use explicit braces, but that doesn't matter. You can fix it with extra braces:

new a;
if (FALSE)
{
    printf("hi");
}
{}
#emit CONST.pri 42
#emit STOR.S.pri a
printf("%d", a);

I thought this was fixed long ago, but I just spent ages tracking down a bug that turned out to be caused by this.

Environment:

  • Operating System
  • Compiler version
  • How are you invoking the compiler? Pawno, Sublime, vscode, sampctl or command-line?
  • If using sampctl, the version number

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions