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-10595] Complex Generic Statements Cause Compiler Segfault #52995

Closed
swift-ci opened this issue May 1, 2019 · 5 comments
Closed

[SR-10595] Complex Generic Statements Cause Compiler Segfault #52995

swift-ci opened this issue May 1, 2019 · 5 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 key paths Feature: key paths (both native and Objective-C)

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2019

Previous ID SR-10595
Radar rdar://problem/50370326
Original Reporter trevorthoele (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10.2

Swift 5

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

md5: 1c939a5b8c0482025aa3b5f50db147ff

duplicates:

  • SR-10128 Compiler crashes when generic type constraint is the associated type of another protocol which the class also conforms to which and has a default implementation

Issue Description:

Not exactly sure what's going on here: mainly that the below code segfaults the compiler.

protocol Nested {
    associatedtype U
}


class A<M> {
    func f<T : Nested>(_ t: T, _ keyPath: WritableKeyPath<M, T.U>) {}
}


class B<Y> : Nested {
    var i: Y?
}


class C<M> {
    func cFunc(_ a: A<M>) {
        let function: (B<Int>, ReferenceWritableKeyPath<M, Int>) -> Void = a.f
    }
}
@belkadan
Copy link
Contributor

belkadan commented May 1, 2019

On near-master, I get

<stdin>:11:7: error: type 'B<Y>' does not conform to protocol 'Nested'
class B<Y> : Nested {
      ^
<stdin>:2:20: note: protocol requires nested type 'U'; do you want to add it?
    associatedtype U
                   ^

but then

Assertion failed: ((conformingReplacementType->is<ErrorType>() || conformingReplacementType->is<SubstitutableType>() || conformingReplacementType->is<DependentMemberType>()) && "replacement requires looking up a concrete conformance"), function operator(), file /Volumes/Data/swift-public/swift/lib/AST/Type.cpp, line 2931.
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -emit-module-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--f5dce8.swiftmodule -emit-module-doc-path /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--f5dce8.swiftdoc -target x86_64-apple-darwin18.6.0 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode10.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -g -enable-anonymous-context-mangled-names -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--f5dce8.o 
1.  Swift version 5.0-dev (LLVM f0b886e419, Swift b44d3490dc)
2.  While type-checking 'cFunc(_:)' (at <stdin>:17:5)
3.  While type-checking statement at [<stdin>:17:27 - line:19:5] RangeText="{
        let function: (B<Int>, ReferenceWritableKeyPath<M, Int>) -> Void = a.f
    "
4.  While type-checking declaration 0x7fc1a403ad60 (at <stdin>:18:9)
5.  While type-checking expression at [<stdin>:18:76 - line:18:78] RangeText="a."

@swift-ci
Copy link
Collaborator Author

Comment by Terence yan (JIRA)

This is a duplicate of [SR-10128]

@belkadan
Copy link
Contributor

Hm, are you sure? It doesn't look like the same problem to me. @slavapestov, what do you think?

@kmahar
Copy link

kmahar commented May 24, 2019

In case it's helpful, I'm seeing a very similar/the same segfault from this code sample on 5.0.1 as well as latest the 5/24 5.1 dev snapshot.

protocol Operation {
    associatedtype OperationResult
    func execute() throws -> OperationResult
}

struct SomeOperation<T: Codable>: Operation {
    let type: T.Type    
    init(type: T.Type) {
        self.type = type
    }
}

func executeOperation<T: Operation>(_ operation: T) throws -> T.OperationResult {
    return try operation.execute()
}

func doSomeOperation<T: Codable>(type: T.Type) throws -> Int {
    let operation = SomeOperation(type: type)
    return try executeOperation(operation)
}

@slavapestov
Copy link
Member

We fixed this a while back - #24886

@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 key paths Feature: key paths (both native and Objective-C)
Projects
None yet
Development

No branches or pull requests

5 participants