You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Also seems to be present in Swift 5
Additional Detail from JIRA
Votes
1
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 516ea1ec593c1b61178384afe9c7df85
relates to:
SR-5440 Typealias in constrained extension misinterprets the where clause
Issue Description:
This is a magical behavior, and it should be disallowed as it's a source of potential ambiguity issues in a more complex project.
protocolTest {
associatedtypeSomethingvarsomething: Something { get }
}
// This is a 'conditional' extension which should not be picked// by the compiler to satisfy protocol conformance automatically// when the conforming type does not provide any requirements// until the explicitly stated that `Something` should be of type `Int`extensionTestwhereSomething == Int {
varsomething: Something {
return42
}
}
structS: Test {} // THIS SHOULD ERROR OUTprint(S().something) // prints 42
Similar example where the default associated type is simply overriden/ignored:
protocolTest {
associatedtypeSomething = Stringvarsomething: Something { get }
}
extensionTestwhereSomething == Int {
varsomething: Something {
return42
}
}
structS: Test {}
print(S().something) // again an Int and not String
I think this is correct behavior; otherwise we wouldn't be able to provide default implementations in the standard library that include a default associated type, and that's important for protocols that have associated types that are mostly just implementation details. cc @airspeedswift, @lorentey
Right – this is the correct current behavior and is used to provide functionality for types like Collection. Changes to it would need to be evolution pitches rather than jiras.
Environment
Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Also seems to be present in Swift 5
Additional Detail from JIRA
md5: 516ea1ec593c1b61178384afe9c7df85
relates to:
Issue Description:
This is a magical behavior, and it should be disallowed as it's a source of potential ambiguity issues in a more complex project.
Similar example where the default associated type is simply overriden/ignored:
Discussion on the forums: https://forums.swift.org/t/what-kind-of-magic-behavior-is-this/22014
The text was updated successfully, but these errors were encountered: