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

[SR-10011] Raw string with 1 double quote give compiler error about multi line strings #52414

Closed
swift-ci opened this issue Feb 27, 2019 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers parser Area → compiler: The legacy C++ parser

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10011
Radar None
Original Reporter MrLotU (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 5.0 Snapshot from February 26, 2019

swift --version && uname -a output:

Apple Swift version 5.0-dev (LLVM 3207a50965, Clang 72dde1b133, Swift fa5d493110) Target: x86_64-apple-darwin18.2.0
Darwin LotU-MacBook-Pro.local 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64 

Platform: MacOS

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, Parser, StarterBug
Assignee maustinstar (JIRA)
Priority Medium

md5: 149b5f8191cb3508a0fd3fbf217154b8

Issue Description:

With the new raw strings in Swift 5, double quotes (") don't have to be escaped anymore (")

However, if I wanted a string containing just " an error will occur.
The code would look like this:

let str = #"""#

where I'd get the following compiler errors:

Multi-line string literal content must begin on a new line
// AND
Unterminated string literal

If you need any more info, feel free to ping me 🙂

@belkadan
Copy link
Contributor

cc @rintaro, @johnno1962

@rintaro
Copy link
Mannequin

rintaro mannequin commented Mar 1, 2019

Currently, the Lexer eagerly eats #""" as the start of multiline text. To fix this, we have to handle this specially.
I'm going to mark this as StarterBug because this issue is not critical, and fix will be almost pure addition to the `Lexer.cpp`.
The fix will be something like:
Here https://github.com/apple/swift/blob/791b81f9/lib/Parse/Lexer.cpp#L1845-L1848

if (Multiline string starts with non-newline character) {
    if (The starting quote starts with '#'*n &&
        There is '"' followed by '#'*n *on the same line*) {
       // Treat it as a single line string literal.
    }
}

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 5, 2019

Comment by Michael Verges (JIRA)

I'd like to take this on as my first bug if that is okay. I think I have it working thanks to @rintaro's guidance. I'll spend some more time making sure everything works.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 6, 2019

Comment by Michael Verges (JIRA)

Please check out this PR to resolve this:

#23115

@swift-ci
Copy link
Collaborator Author

Comment by Michael Verges (JIRA)

#34414

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself good first issue Good for newcomers parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

2 participants