[swift-users] Compiler crashes while resolving generics constraints

Slava Pestov spestov at apple.com
Sun Dec 25 14:50:41 CST 2016


Hi Igor,

Your example is not self-contained, so I added the following definitions:

struct URI {}

struct App {
  class Remote {
    struct Credentials {} 
  }
}

struct RemoteUser {}

protocol ResponseRepresentable {}

protocol RemoteCredentials {}

Unfortunately, this makes the code compile in both Swift 3.0 and the latest code built from GitHub, even with the ‘where’ part uncommented, so I suspect we’ll need a larger testcase to reproduce the original issue.

However from looking at the code, what you’re doing is adding a requirement to an associated type of the ‘Self’ generic parameter, which Swift 3.0 did not model properly, but it is one of the things we addressed in some recent refactoring work.

Could you try the latest development snapshot from swift.org <http://swift.org/> and let us know if it solves your problem?

Slava

> On Dec 25, 2016, at 1:05 PM, Игорь Никитин via swift-users <swift-users at swift.org> wrote:
> 
> Hello!
> 
> I have few protocols with associated types:
> protocol Remote {
>     associatedtype Credentials: RemoteCredentials
> 
>     static var url: URI { get }
>     static var name: String { get }
>     static var credentials: Credentials.Type { get }
> }
> protocol RemoteAuthenticating {
>     associatedtype Remote: App.Remote
> 
>     func authenticate(with credentials: Remote.Credentials) throws -> (RemoteUser, ResponseRepresentable?)
> }
> protocol RemoteAuthenticationServiceBuilder {
>     associatedtype Service: RemoteAuthenticating
> 
>     // TODO: `Service.Remote` should be constrained to `Remote` but compiler crashes
>     func authenticationService<Remote: App.Remote>(for: Remote.Type) -> Service? // where Service.Remote == Remote
> }
> It works fine until I uncomment the last where statement
> If I trying to constraint Service.Remote type compiler will crash with segfault 11
> I can guess that it's a compiler bug, but maybe I’m using generics in wrong way?
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161225/0660a4cd/attachment.html>


More information about the swift-users mailing list