Skip to content

Disallow multi-line filenames and non-decimal line numbers in #sourceLocation directive in Swift 6 mode #71238

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

Merged

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 30, 2024

  • Disallow non-decimal line numbers to #sourceLocation directive
    • Non-decimal line numbers in a #sourceLocation directive are simply confusing in my opinion and should be banned.
  • Disallow multiline string literals for filename in #sourceLocation and similar locations
    • This should allow us to eventually simplify parsing of simple string literals in the new parse by not having to handle indentation of multiline string literals.

Non-decimal line numbers in a `#sourceLocation` directive are simply confusing in my opinion and should be banned.
Comment on lines 17 to 27
// expected-warning@+1 {{expected starting line number for #sourceLocation directive; this is an error in Swift 6}}
#sourceLocation(file: "x.swift", line: 0xff)

#sourceLocation()

// expected-warning@+1 {{'#sourceLocation' cannot be a multiline string literal; this is an error in Swift 6}}
#sourceLocation(file: """
x.swift
y.swift
""", line: 42)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth adding tests for the error variants of these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think that’s necessary. The this is an error in Swift 6 is generated automatically by the warnUntilSwiftVersion(6) and should just work.

Comment on lines 22 to 26
// expected-warning@+1 {{'#sourceLocation' cannot be a multiline string literal; this is an error in Swift 6}}
#sourceLocation(file: """
x.swift
y.swift
""", line: 42)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For e.g #sourceLocation(file: "a\nb", line: 42), seems we just take the characters literally, not sure if we ought to ban escape sequences too to avoid confusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting. Let’s consider that a separate issue though. It’s probably not worth fixing it in the old parser anyway.

@ahoppen ahoppen force-pushed the ahoppen/source-location-parser-changes branch from b133f5f to e6b41b7 Compare January 31, 2024 01:23
@ahoppen
Copy link
Member Author

ahoppen commented Jan 31, 2024

@swift-ci Please smoke test

…ation and similar locations

This should allow us to eventually simplify parsing of simple string literals in the new parse by not having to handle indentation of multiline string literals.
@ahoppen ahoppen force-pushed the ahoppen/source-location-parser-changes branch from e6b41b7 to 4a386d4 Compare February 1, 2024 00:03
@ahoppen
Copy link
Member Author

ahoppen commented Feb 1, 2024

@swift-ci Please smoke test

@ahoppen ahoppen enabled auto-merge February 1, 2024 00:03
@ahoppen ahoppen merged commit 12fe866 into swiftlang:main Feb 1, 2024
@ahoppen ahoppen deleted the ahoppen/source-location-parser-changes branch February 3, 2024 03:43
ahoppen added a commit to ahoppen/swift that referenced this pull request Feb 3, 2024
…e-location-parser-changes"

This reverts commit 12fe866, reversing
changes made to 956d6d2.
ahoppen added a commit to ahoppen/swift that referenced this pull request Feb 23, 2024
…e-location-parser-changes"

This reverts commit 12fe866, reversing
changes made to 956d6d2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants