Skip to content

Implement inheritance of initializers with generic parameters [4.2] #17390

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
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2a71adb983ae7682cb74e3b18014a31663323a4f

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2a71adb983ae7682cb74e3b18014a31663323a4f

@slavapestov slavapestov force-pushed the generic-init-inheritance-4.2 branch from 2a71adb to 77d5df7 Compare June 22, 2018 03:47
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 77d5df7a5f5e2421bdde959098b4565768578176

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 77d5df7a5f5e2421bdde959098b4565768578176

@slavapestov slavapestov force-pushed the generic-init-inheritance-4.2 branch from 77d5df7 to 3c3d31a Compare June 22, 2018 06:20
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 77d5df7a5f5e2421bdde959098b4565768578176

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 77d5df7a5f5e2421bdde959098b4565768578176

@slavapestov slavapestov force-pushed the generic-init-inheritance-4.2 branch from 3c3d31a to eb35069 Compare June 22, 2018 08:01
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3c3d31aede571d5b03fd5d666a7b4b49153b5bec

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov force-pushed the generic-init-inheritance-4.2 branch from eb35069 to 09aea61 Compare June 22, 2018 08:18
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - eb350690b858e14f67834268e5027caf4ba2ea0f

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - eb350690b858e14f67834268e5027caf4ba2ea0f

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - eb350690b858e14f67834268e5027caf4ba2ea0f

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 5511c09 into swiftlang:swift-4.2-branch Jun 22, 2018
}

// We don't have to clone the requirements, because they're not
// used for anything.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't they get printed sometimes? Like, for quick help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be printing generic signatures, not generic parameter lists. RequirementReprs are not serialized.

superclassDepth = genericSig->getGenericParams().back()->getDepth() + 1;

// We're going to be substituting the requirements of the base class
// initializer to form the requirements of the derived class initializer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm clearly extra sensitive to this now because of the other issue, but what happens if the constraints can't be satisfied?

class Base<Wrapped> {
  init() {}
  init<Num: Numeric>(absoluteValueOf: Num) where Num.Magnitude == Wrapped {}
}

class Sub: Base<String> {}
_ = Sub(absoluteValueOf: "bac")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fails:

<unknown>:0: error: generic parameter 'Num' could not be inferred

I guess that's not great, but I'm not sure what the best solution is. Just drop the initializer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping it's probably the best option for now. Who knows what would happen if it was required?

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.

3 participants