Skip to content

[SR-12354] [5.2] [regression] Types no longer conform to protocol #54788

Closed
@swift-ci

Description

@swift-ci
Previous ID SR-12354
Radar rdar://problem/60383688
Original Reporter tannernelson (JIRA User)
Type Bug
Environment

Xcode Version 11.4 beta 3 (11N132i)
macOS 10.15

Additional Detail from JIRA
Votes 6
Component/s Compiler
Labels Bug, 5.2Regression, AssociatedTypeInference
Assignee None
Priority Medium

md5: bdc582c5c5b3ebba399c6dbb3afaae12

Issue Description:

https://github.com/vapor/api-template @ af8148b447a16f22db819737ad97da9beef634f5
https://github.com/nodes-vapor/jwt-keychain @ 55dd5703e90c8c673ac62051aca312541a8c40f2

These two projects show examples of a regression in the Swift 5.2 compiler causing many Vapor 3 projects to not compile. To reproduce the bug, compile those commit hashes with Swift 5.2.

The regression is based around this code:

public protocol Model {
    associatedtype Database
}

Each database package introduces types like:

public protocol MySQLModel: Model
    where Self.Database == MySQLDatabase 
{ }

In 5.1 and earlier this allowed for declarations of models to look like:

final class Todo: SQLiteModel {
    ...
}

However, with 5.2, the `Database` typealias must be provided even though it is constrained to a specific type by the protocol being conformed to.

final class Todo: SQLiteModel {
    // Swift 5.2 requires this even though SQLiteModel constrains Database
    // to this exact type. 
    typealias Database = SQLiteDatabase
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    associated type inferencebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfregressionswift 5.2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions