Navigation Menu

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-10108] Adding associated value to enum throws segmentation fault: 11 and crashes Xcode. #52510

Closed
swift-ci opened this issue Mar 14, 2019 · 8 comments
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

Comments

@swift-ci
Copy link
Collaborator

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

Attachment: Download

Environment

I am using Xcode Version 10.1 (10B61) and Swift 4.2 with macOS Mojave 10.14.3.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @theblixguy
Priority Medium

md5: 8ae1dbd92a842e87321189c5c0feb7de

Issue Description:

if I add an associated value to enum case, Xcode throws me an error: An internal error has occurred. Source editor functionality is limited. Attempting to restore... and building the project shows me segmentation fault: 11.

I know enums with raw values cannot have associated values but instead of crashing Xcode compiler should throw me an error right?

I have attached the source code when this is happening and screenshot of error it is throwing.

Please let me know if you need anything else.

P.S.: This is my first bug report on Swift and I am pretty noob in Swift programming. Please forgive me if it's really not a bug in swift but an error from my side.

@belkadan
Copy link
Contributor

Thanks for reporting this! I think this is an issue we fixed in Swift 5 / Xcode 10.2, but can you attach your source as a text file so we can be sure?

@swift-ci
Copy link
Collaborator Author

Comment by Anmol Malhotra (JIRA)

Omg. 😃 Can't believe I actually found a bug in Swift. 😛

I will upload my source file as first thing in the morning once I reach my office.

Thanks a lot for replying @belkadan. Big fan. 🙂

@swift-ci
Copy link
Collaborator Author

Comment by Anmol Malhotra (JIRA)

Hey @belkadan, I have added the source file in attachments. Let me know if you need anything else.

@theblixguy
Copy link
Collaborator

Can't reproduce on master. Tried with 4.2 as well, but it compiles fine. Is this the correct source file? anmol (JIRA User)

@swift-ci
Copy link
Collaborator Author

Comment by Anmol Malhotra (JIRA)

Hey @theblixguy, I uploaded the file without the bug. Sorry about that. Please try now. Let me know if you need anything else.

@theblixguy
Copy link
Collaborator

Thanks! I can reproduce this on 5.1. What's causing this to happen is the initialiser in the extension on the enum, which is called when initialising the static property. This causes the compiler to (try) synthesise raw representable conformance even though we can't do that with enum cases that have a payload. Here's a reduced test case:

enum Crash: String {
  case foo
  case bar(String)
  static let shared = Crash()
}

extension Crash {
  init() {
    self = .foo
  }
}

The fix for this is basically to not do that. I'll open a PR to fix this shortly.

@theblixguy
Copy link
Collaborator

PR: #23357

@theblixguy
Copy link
Collaborator

Fixed on master. I have cherry picked the fix to the 5.1 branch too.

@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
Projects
None yet
Development

No branches or pull requests

4 participants