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-13215] Default implementation of dynamic member lookup subscript in protocol extension causes segfault 11 #55655

Closed
swift-ci opened this issue Jul 14, 2020 · 2 comments
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-13215
Radar None
Original Reporter marcusrossel (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment
  • Xcode version Version 11.5 (11E608c)

  • macOS 10.15.5 (19F101)

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

md5: 767161678d25ac02a65f85ea6bb6b8dc

duplicates:

  • SR-12425 Swift 5.2 Regression: Segfault when type of dynamic member key path doesn't match instance type

Issue Description:

This code snippet causes the compiler to fail with a Segmentation fault 11:

@dynamicMemberLookup
protocol FuzzyDecodable: Decodable {
  associatedtype CodingKeys: CodingKey, RawRepresentable where CodingKeys.RawValue == String
  subscript<T>(dynamicMember keyPath: KeyPath<Self, T>) -> T { get set }
  init(from decoder: Decoder) throws
}

extension FuzzyDecodable {
  subscript<T>(dynamicMember keyPath: KeyPath<Self, T>) -> T {
    get { self[keyPath: keyPath] }
    set { self[keyPath: keyPath] = newValue }
  }
}
@theblixguy
Copy link
Collaborator

This seems to be fixed on Xcode 12 beta and it no longer crashes. You now get the following diagnostic:

<source>:11:15: error: cannot assign through subscript: 'keyPath' is a read-only key path
    set { self[keyPath: keyPath] = newValue }
          ~~~~^~~~~~~~~~~~~~~~~~

Your subscript needs to take either a WritableKeyPath or ReferenceWritableKeyPath depending on whether you're working with value types or reference types.

@LucianoPAlmeida
Copy link
Collaborator

@theblixguy I think this is the same problem as SR-12425 and SR-12626, so maybe could be resolved as a dupe.

@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

4 participants