fusionlanguage/fut

false positive error inside #if condition?

Closed this issue · 1 comments

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?

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.