Skip to content

Concrete type inheriting two typealias with the same name from two protocols arbitrarily chooses one of them in a generic function. #84301

@michelf

Description

@michelf

Description

No response

Reproduction

protocol P { }
extension P { typealias B = String }

protocol Q { }
extension Q { typealias B = Int }

func f<T: P & Q>(_: T) {
	var x: T.B // type is ???
}

With some experiment (keeping everything in the same module) it looks like the compiler resolves this by picking the first protocol with a B type in it, in alphabetical order of the protocol name.

Expected behavior

Probably an ambiguity error of some kind. It's unfortunate there's no way to disambiguate though.

Environment

Tested with either Xcode 16.3 or 26 RC, not sure which one and I can't check at the moment.

Additional information

Recopied from https://forums.swift.org/t/se-0491-module-selectors-for-name-disambiguation/82124/21

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions