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
When there are default protocol implementation, constrained protocol extension implementation, type implementation, constrained type extension implementation, of an API, which one is actually called is very confusing and some current behaviors are quite odd.
I think:
The definite dispatching rules should specified and documented.
Some of current behaviors are bugs — though I'm not sure which because I'm not sure about the dispatching rules — and should fixed.
Commented code with execution results should explain the issues more clearly:
protocolP {
typealiasTfuncf()
funcg()
}
extensionP {
funcf() {
print("P.f")
}
funcg() {
print("P.g")
f() // Should call P.Equatable.f if T is Equatable, shouldn't it?
}
}
extensionPwhereT: Equatable {
funcf() {
print("P.Equatable.f") // Inaccessible to P.g? Not even to P.Equatable.g but accessible to to Foo.Equatable.g — odd.
}
// func g() {// print("P.Equatable.g")// f() // Should call P.Equatable.f if T is Equatable, shouldn't it?// }
}
structFoo<U>: P {
typealiasT = U// func g() {// print("Foo.g")// f()// }
}
extensionFoowhereU: Equatable {
// func f() {// print("Foo.Equatable.f") // Inaccessible to P.g or Foo.g? At least accessible to Foo.Equatable.g.// }// func g() {// print("Foo.Equatable.g")// f()// }
}
letfoo = Foo<Int>()
foo.f()
print("")
foo.g()
// Uncomment P.Equatable.g, Foo.g, Foo.Equatable.g, Foo.Equatable.f to see other behaviors.
The actual output:
P.Equatable.fP.gP.f
The expected output:
P.Equatable.fP.gP.Equatable.f
The text was updated successfully, but these errors were encountered:
Looks like the compiler selects the less specific method for the witness table. Instead of selecting the method that prints "P.Equatable.f" it selects the one that prints "P.f".
Additional Detail from JIRA
md5: ebc1bb2c8590dd5c9b38b1264038435b
Issue Description:
When there are default protocol implementation, constrained protocol extension implementation, type implementation, constrained type extension implementation, of an API, which one is actually called is very confusing and some current behaviors are quite odd.
I think:
Commented code with execution results should explain the issues more clearly:
The actual output:
The expected output:
The text was updated successfully, but these errors were encountered: