Code Parser Can Fail When a Line Contains Both a CasePath Literal and a String Literal with a / Character #115
aetherealtech
started this conversation in
General
Replies: 1 comment
-
@aetherealtech Unfortunately this behavior is on the compiler and not something we have control over. Because of this, I'm going to convert this to a discussion since we use issues for tracking library bugs that we have an ability to fix. If you believe the Swift compiler should be up to the task of parsing the above line, I recommend filing a bug directly with Apple: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
If a single line in a Swift source file contains a case path literal, which is started with a
/
, and then later in the same line, a string literal contains a/
character, the code parser will act strangely, highlighting the code incorrectly (as if everything between the two/
characters is a string literal), and sometimes (but not always) fail to compile. The parser is probably assuming the two/
are demarcating a regex literal.I discovered this when I was trying to commit a file and kept getting an "unexpected end of file" error, which turned out to be coming from a pre-commit hook that runs a formatting tool. In that case, the file compiled fine, although the code was highlighted incorrectly. In the sample projected I am attaching, it fails to compile.
A simple workaround is to split the expression into multiple lines.
This is probably a bug in the parser, but I wanted to bring attention to it here first.
To Reproduce
Sample project attached shows the workaround and the problem. For whatever reason, where I originally encountered this in my code base, the compiler accepted it but then the parser in Xcode, and a tool that parses code, choked. But in this sample, the compiler chokes too.
TestCasePathParse.zip
Expected behavior
The parser should work the same way for a single line as it does when the expression is split onto multiple lines.
Screenshots
Environment
Beta Was this translation helpful? Give feedback.
All reactions