Skip to content
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

Fix missing diagnostics about the lack of initializers in cross-module inheritance scenarios #70219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DougGregor
Copy link
Member

When a class inherits a superclass from another module, and that superclass has non-public designated initializers, two important diagnostics were being suppressed:

  • The diagnostic about any required initializers in the superclass that couldn't be synthesized in the subclass, and
  • The diagnostic about the lack of any initializers in the subclass.

Between the two, it became possible to create a class that could not be initialized statically (doing so would produce an error), but that could be dynamically created via the required initializer---without initializing the subclass's storage. Introduce diagnostics for both, staging them in via warnings in Swift 5 and becoming errors in Swift 6.

Fixes #69965

In cases where a subclass was unable to synthesize any initializers
(for example, because there were missing designated initializers in the
superclass), we were skipping checking of superclass required
initializers. This meant that we would silently accept subclasses that
cannot be initialized directly (that would produce an error), but
could at runtime be initialized via a required initializer... that
didn't account for the subclass.

Fixes the original problem from swiftlang#69965,
but not the most minimal one.
…ssing ones

The presence of a superclass from another module that has missing
designated initializers was suppressing the diagnostic complaining
about a class having no initializers. Start complaining about such
classes when the superclass comes from Swift, but downgrade the error
to a warning prior to Swift 6 so we don't break existing code.

Fixes swiftlang#69965.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge December 5, 2023 00:30
@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

Ah, it looks like we have a few other instances of this pattern in our test suite that I'll need to fix up.

@DougGregor
Copy link
Member Author

I'm splitting this into two different PRs. The most critical fix is the required initializer change, because that's a proper soundness hole in the system, and is now covered by #70236.

The second fix (of the "no constructors of class...") needs more work.

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.

Subclass compiles without initializing properties
1 participant