Parse errors when conditional directives are combined with raw string literals #7520
Replies: 6 comments 5 replies
-
This also happens with the verbatim strings. The ambiguity will still be there anyway if the verbatim/raw string contains syntactically valid directives though :/ |
Beta Was this translation helpful? Give feedback.
-
This is a request for a language change. The compiler is working as per the language rules here. I'm wary about any changes here because of hte potential for regressions. |
Beta Was this translation helpful? Give feedback.
-
Is the current behavior well-spec'ed? If so, can you move this as a discussion to csharplang? |
Beta Was this translation helpful? Give feedback.
-
Yes, it's spec'ed here: https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/lexical-structure.md#65-pre-processing-directives |
Beta Was this translation helpful? Give feedback.
-
I'm confused now. From https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/lexical-structure.md#65-pre-processing-directives It sounds like "pre-processing directives" are not processed, but are still parsed. Basically, you cannot have a line inside any multi-line string which starts with a "#", except if it happens to be valid directive. If this is correct, then:
Or am I missing something? |
Beta Was this translation helpful? Give feedback.
-
I can see why that fails, but I'm wondering if this can be improved. I think that when the compiler encounters a conditional directive that evaluates to false, it should try to keep going until it finds a valid directive trivia.
So instead of parsing "# Hello raw string literals" with as "BadDirectiveTrivia", it should be parsed as DisabledTextTrivia and continue searching for a valid directive trivia, which is going to be #endif
cc @CyrusNajmabadi
Beta Was this translation helpful? Give feedback.
All reactions