Skip to content

[SR-7217] Protocol composition with conflicting typealiases does not diagnose #49765

Open
@itaiferber

Description

@itaiferber
Previous ID SR-7217
Radar None
Original Reporter @itaiferber
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: c5f27b0f94d34e042696e3afc9cf3681

relates to:

  • SR-7516 Compiler accepts ambiguous and/or invalid use of associated types
  • SR-5392 Inconsistent "invalid redeclaration of typealias"
  • SR-5440 Typealias in constrained extension misinterprets the where clause

Issue Description:

From discussion in https://forums.swift.org/t/decode-a-json-object-of-unknown-format-into-a-dictionary-with-decodable-in-swift-4/6138/38, the following typealias conflict produces no diagnostics in Swift 4.1:

struct Foo {}
struct Bar {}

protocol P1 { typealias T = Foo }
protocol P2 { typealias T = Bar }

typealias P3 = P1 & P2
print(P3.T.self) // => Bar()

typealias P4 = P2 & P1
print(P4.T.self) // => Bar()

Code completion shows two overloads for P3.T and P4.T but there are no warnings or complaints otherwise. The ordering of the composition makes no difference on which type "wins out".

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfprotocolFeature → type declarations: Protocol declarationsprotocol compositionsFeature → types: protocol composition typesswift 6.0type checkerArea → compiler: Semantic analysistype declarationsFeature → declarations: Type declarationstypealiasFeature → type declarations: `typealias` declarationstypesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions