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-4382] Raw value type alias in raw representable child is no longer recognised #46961
Comments
This syntax was only ever meant to set a default, not constrain adopters. But it is a behavior change. cc @huonw, @slavapestov. |
Good point. Is it possible though? |
To constrain adopters? There's a Swift 4 feature for that, but it isn't finished yet. |
You can get 90% of the way there by adding a requirement |
Good point! Will give it a go. |
To set a new default in a refined protocol, use an associated type:
I don't think the intent of the old behavior of typealiases that shadow a protocol was to set defaults or really do anything at all. It was unsound and unfortunately we had to break some marginally valid code in order to put this on a more logical foundation. |
That just changes the default; it does not enforce it. |
I'm not sure I understand then. If you want to set a default, you can use 'associatedtype'. To constrain adopters, you can use a 'typealias'. |
A typealias doesn't constrain adopters. It's just another default (by being another candidate). |
@slavapestov, @DougGregor, and I talked some offline and realized that
But here's a dummy example that both 3.0 and 3.1 accept where the typealias is not picked as the associated type:
This outputs
which is pretty weird but clearly has some semantics. I'm not exactly concerned about a contrived case like this, but it's possible that someone accidentally made the types not match up, and we shouldn't break working code in 4.0's 3-mode. |
I think at this point we're going to stick with the new behavior, which treats this as a constraint on the associated type and suggests you explicitly use a same-type constraint instead. |
Additional Detail from JIRA
md5: 489c9dccf042078477e3462cc0156ed5
is duplicated by:
Issue Description:
The following declaration of RawValue in inheriting protocol used to work right before updating to 3.1.
The text was updated successfully, but these errors were encountered: