Skip to content
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

false positive error inside #if condition? #162

Closed
iAndyHD3 opened this issue May 10, 2024 · 1 comment
Closed

false positive error inside #if condition? #162

iAndyHD3 opened this issue May 10, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@iAndyHD3
Copy link
Contributor

It appears that code inside of false evaluated #if conditions is skipped, as such this code does not produce any errors

#if TEST
ksdfj
jkkfjlkas
#endif

However, this valid code dos not compile if TEST is not defined, which means code is not being skipped correctly? If TEST is defined, it compiles as expected

#if TEST
class Test
{
    public static void Main()
    {
        int a = 0;
        Console.WriteLine($"{a}"); //Test.fu(7): ERROR: Unterminated string literal
    }
}
#endif

Another error that isn't being skipped correctly: (TEST is not defined)

#if TEST
0a //Test.fu(2): ERROR: Invalid integer
#endif

Unrelated:
If I have a few small suggestions and questions, should I post them in Discussions?

@pfusik pfusik added the bug Something isn't working label May 11, 2024
@pfusik
Copy link
Collaborator

pfusik commented May 11, 2024

It appears that code inside of false evaluated #if conditions is skipped, as such this code does not produce any errors

#if TEST
ksdfj
jkkfjlkas
#endif

This is expected. Code under a false condition is not parsed. Same as with C, C++ and C# compilers.

Why?

  1. With 20 conditional variables, there are over 1 million code cases to be checked.
  2. Some combinations of condition variables might be invalid, e.g.
class Foo {
#if INTERNAL
    internal
#endif
#if PROTECTED
    protected
#endif
    int Bar;
}

However, this valid code dos not compile if TEST is not defined, which means code is not being skipped correctly? If TEST is defined, it compiles as expected

#if TEST
class Test
{
    public static void Main()
    {
        int a = 0;
        Console.WriteLine($"{a}"); //Test.fu(7): ERROR: Unterminated string literal
    }
}
#endif

This is a bug. Interpolated strings need a cooperation between the parser and the lexer and the parser is disabled for false conditions.

Another error that isn't being skipped correctly: (TEST is not defined)

#if TEST
0a //Test.fu(2): ERROR: Invalid integer
#endif

This is expected. Code under a false condition must be a valid token sequence as it gets lexed.

Why?
There might be a /* opening a multi-line comment which comments-out the #endif. But we can't just search for /* characters because they might be in a string literal ("/*") or a single-line comment (// /*).

Unrelated: If I have a few small suggestions and questions, should I post them in Discussions?

If you have specific bug reports or feature requests, post them in Issues.
For generic discussion and questions, use Discussions.

@pfusik pfusik self-assigned this May 11, 2024
@pfusik pfusik closed this as completed in feefdcf May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants