New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-9686] Swift 5 regression: extension applied to type alias not "seen" #52128
Comments
Hm. @slavapestov, how does this relate to your fix for SR-631? |
I think I introduced this failure with #18539 . Dictionary only has a nested type named `Value`through indirect means that involve the full type checker (associated type inference, IIUC), which is a layering violation in the compiler that we're trying to eliminate. The language could accommodate this example directly with the (IMO reasonable) extension described at https://forums.swift.org/t/allow-member-lookup-to-find-generic-parameters/7768 |
It is annoying that we don't get a more-specific diagnostic about our inability to bind this extension, though. That makes it much harder to see what the problem is. |
Oh, it's because of the substitution in the typealias. I don't know that future language changes would alter this at all—at best I hope we get a better diagnostic for it. |
Arguably we should get it from Dictionary's generic parameter, no? |
Getting it from Dictionary's generic parameter effectively means implementing some of the "substitution" logic needed to resolve a member of a generic type that involves other type parameters. One could handle simple cases of this, but the general case is "all of type checking," and it feels like it might be easier to explain in terms like "cannot name a generic parameter". |
Yeah, I think it makes sense to prohibit extensions from naming a type alias whose underlying type is a dependent type. |
Behaves correctly in 5.7: /private/tmp/SR-9671/swift-server-logger-api/Sources/Logging/Logging.swift:295:1: error: extension of type 'Logging.Metadata.Value' (aka 'Logging.MetadataValue') must be declared as an extension of 'Logging.MetadataValue'
extension Logging.Metadata.Value: ExpressibleByStringInterpolation {
^ ~~~~~~~~~~~~~~~~~~~~~~
/private/tmp/SR-9671/swift-server-logger-api/Sources/Logging/Logging.swift:295:1: note: did you mean to extend 'Logging.MetadataValue' instead?
extension Logging.Metadata.Value: ExpressibleByStringInterpolation {
^ ~~~~~~~~~~~~~~~~~~~~~~
Logging.MetadataValue |
Additional Detail from JIRA
md5: e92e8c40edeaa38d9111378b8f591e2e
is duplicated by:
Issue Description:
I believe I found a regression in Swift 5 ( 5.0-DEVELOPMENT-SNAPSHOT-2019-01-16-a ) with regards to 4.2 while working on the logging proposal for the server side swift working group (so context is: https://github.com/weissi/swift-server-logging-api-proposal ).
I'm using these types in a library which is cross compiled for 4.2 and development builds of Swift 5 so noticed it there. The following self contained snippet isolates the issue:
The important bit being that we extend `Logging.Metadata.Value` via the alias through `Metadata`. This works on swift 4.2 but not on 5:
If we avoid touching the alias it works on all Swift versions:
I would hope to be able to use the alias version since this way we have an uniform way to address Key/Value, by always saying
Logging.Metadata.Key
/Logging.Metadata.Value
etc.The text was updated successfully, but these errors were encountered: