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-12998] Raw Value of literal String #file breaks enum with String Protocol #55443

Closed
swift-ci opened this issue Jun 12, 2020 · 4 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12998
Radar None
Original Reporter 0-1 (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, TypeChecker
Assignee @theblixguy
Priority Medium

md5: da1a27a777b6be474b5c910416171f6d

relates to:

  • SR-13022 Support magic literals as enum case raw value

Issue Description:

Bug with #file

enum Foo: String {

{{ case bar = #file}}

{{}}}

This causes an internal error: Segmentation Fault: 11

Is #file considered a literal String?

"(5)" is not a literal. But Apple's Swift 5.2 Guide describes #file, #line, #function, #colorLiteral, etc. all as literals.

___

Bug with nil

enum I:Int?{

{{ case a = nil}}

{{}}}

@theblixguy
Copy link
Collaborator

The problem is that the value associated with the magic literals are not available in the type checker (they're emitted in SILGen), which means we can't do a uniqueness check. I suppose we could make it work by only allowing only one magic literal of each kind to be associated with an enum case (i.e. you can't have two cases of #line) but I am not sure if that's a better rule than not allowing magic literals in the first place.

Regardless, the compiler shouldn't be crashing here, which is a bug.

EDIT: Upon thinking a bit more, I think it's possible to support these literals by moving some of the code from SILGen into AST/Sema. I'll give it a try soon.

@swift-ci
Copy link
Collaborator Author

Comment by Jonathan Pappas (JIRA)

@theblixguy Thank you,

I also found that using ExpressibleByNilLiteral and setting one of the raw values to nil also causes the same issue.

@theblixguy
Copy link
Collaborator

Thanks. I don’t think nil can be supported as it’s not a unique literal. I think the only ones that can potentially be supported is #file, #function, #line and #column.

@theblixguy
Copy link
Collaborator

The crash is now fixed by #32364. I'll create a new SR to track adding support for #file, #filePath, #function, #line and #column.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants