Skip to content

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Mar 28, 2017

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.

…ty_nonoverlapping'

The test tests more than just initializers now.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

import availability_overloads_other

// FIXME: Should this work?
#if false
Copy link
Contributor Author

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.
@slavapestov slavapestov force-pushed the non-overlapping-availability-for-properties branch from 1d72342 to 4da2611 Compare March 28, 2017 04:07
@slavapestov slavapestov changed the title Non overlapping availability for properties Allow overloading properties with non-overlapping availability Mar 28, 2017
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov slavapestov merged commit 56ad8bd into swiftlang:master Mar 28, 2017
Copy link
Contributor

@jrose-apple jrose-apple left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@jrose-apple jrose-apple Mar 29, 2017

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())) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@jrose-apple jrose-apple Mar 29, 2017

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.

@slavapestov
Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants