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-7147] Compiler crash (Illegal instruction 4) when working with protocols. #49695

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

swift-ci commented Mar 8, 2018

Previous ID SR-7147
Radar None
Original Reporter marcusrossel (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment
  • XCode Version 9.2 (9C40b)

  • in a standard command-line project

  • on a 2017 MacBook Pro

  • High Sierra Version 10.13.3 (17D102).

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

md5: 438c31914626374ed2849a24c550f4b2

Issue Description:

The code below causes the compiler to emit the following:

warning: redundant conformance constraint 'G2': 'P2'
extension S where G2 == C<S.A2ofG2>
                     ^

Command failed due to signal: Illegal instruction: 4

Code:

protocol P1 { associatedtype A1 }

protocol P2 { associatedtype A2: P1 }

class C<G1: P1>: P2 { typealias A2 = G1 }

struct S<G2: P2> { typealias A2ofG2 = G2.A2 }

extension S where G2 == C<S.A2ofG2> { }
@belkadan
Copy link
Contributor

belkadan commented Mar 9, 2018

Fixed in Swift 4.1!

<stdin>:9:22: error: same-type constraint 'G2' == 'C<G2.A2>' is recursive
extension S where G2 == C<S.A2ofG2> { }
                     ^

@swift-ci
Copy link
Collaborator Author

Comment by Marcus Rossel (JIRA)

Thanks @belkadan! Nice to see the error message fixed.

Please redirect me, if this is the wrong place to ask this...

I was actually assuming that the code shouldn't produce an error at all ^^

What mechanism is there then to constrain `S.G2` to be of type `C`, while still keeping `C.A1` generic?

Perhaps this isn't possible, because the generic `G2` can't only be partially specified? And if so... Is it desired not to allow this, or is this a current limitation of generics?

@belkadan
Copy link
Contributor

I don't think we have a way to spell that yet; it'd be something like

extension <A2ofG2> S where G2 == C<A2ofG2> { }

But I think you can fake it if you only want to put methods in the extension:

extension S {
  func foo<A2ofG2>() where G2 == C<A2ofG2> { }
}

@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

3 participants