-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Improve multi-file enum diagnostics #9180
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
Why are there no interface types in the AST? The enum should be validated before it is referenced from inside any function bodies |
Here's what I'm getting back from this setup: // Test File 1
func f(_ x : Foo) {
switch x {
}
}
// Test File 2
enum Foo {
case bar(Bool)
case baz(Bool)
}
|
Ah, wait: This is an ordering problem. I need everything in the other file to be typechecked before I ask for the interface type of the enum decl. |
Well, you don't want to type check everything in the other file -- that would be a performance problem. However, since the declaration 'Foo' is referenced here, probably all of the enum cases contained therein should also be validated. How was this working before? |
You could try just calling TypeChecker::validateDecl() on the enum case decl before getting its type. |
That works, but it means I have to thread an instance of the typechecker through this whole thing, and probably validate a lot of enum element declarations that will already go through validation. Is there some later phase of semantic analysis I can stick this in to get around that? |
Well, validating a decl more than once is a no-op. We validate all case members of referenced enums later anyway since we need that to compute layouts in IRGen. |
@swift-ci please smoke test |
fa20e48
to
a0b7f57
Compare
Yep, that got it. @swift-ci please test macOS platform |
@swift-ci please smoke test |
Build failed |
@swift-ci please smoke test |
⛵️ |
@CodaFi are you planning to merge this to swift-4.0-branch? |
Along with your last pull request. Just gonna take it all in that one place if that's OK. |
That will be a good idea! Thank you! |
Given a setup where one file declares an enum and the other switches on it, decomposition fails because it can't get any useful interface types out of the AST. Version 1 of this patch adds a short hack that just throws in the enum case constructor heads into the space and reports that back to the user because it's better than nothing, but there's got to be a better way to do this.
@slavapestov?