-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Allow overloading properties with non-overlapping availability #8386
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
Allow overloading properties with non-overlapping availability #8386
Conversation
…ty_nonoverlapping' The test tests more than just initializers now.
@swift-ci Please smoke test |
import availability_overloads_other | ||
|
||
// FIXME: Should this work? | ||
#if false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrose-apple I moved the BeforeAndAfter class into a separate module to make sure we can serialize this stuff properly, too.
Do you think we should be able to override these properties? I guess override checking needs a 'non-overlapping availability' check of some kind too.
This allows library authors to change the type of a computed property from one Swift version to the next.
1d72342
to
4da2611
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was quick! Do we need to change mangling as well, though? Properties don't have symbols but they do have USRs.
@@ -975,6 +976,19 @@ static void checkRedeclaration(TypeChecker &tc, ValueDecl *current) { | |||
isAcceptableVersionBasedChange = true; | |||
} | |||
} | |||
// - or they are computed properties of different types, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one of them can be a stored property, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but what about DI? Even the unavailable property has to be initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine as long as the one that's stored is available in the current language mode.
!currentVD->hasStorage() && | ||
!otherVD->hasStorage() && | ||
!currentVD->getInterfaceType()->isEqual( | ||
otherVD->getInterfaceType())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it might be incorrect if the "redeclaration" is across extension boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean with generic classes and extensions? Do you have an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this, maybe?
class A<T, U> {}
extension A {
@available(swift 4)
var x: T? { return nil }
}
extension A where T == U {
@available(swift, obsoleted: 4)
var x: U? { return nil }
}
I'm just making things up; I don't actually have a test case. (I didn't try this one with your patch or anything.) It just set off warning bells.
Yeah I think the right thing to do is to always mangle the type with the property. I think the only time it would come up is with USRs and stored property field offset symbols (but those are not public AFAIK). I'll make a follow up patch. Thanks for the review! |
This generalizes the logic in #8009 which was recently added by @jrose-apple to allow "overloading" properties with different types as long as they have non-overlapping availability.