-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-12460] Don't crash when missing a type in a Diagnostic message. #30979
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
Print an empty string for the missing type. Resolves SR-12460
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.
Thank you for the contribution! I'd suggest we actually fix declaration checker to verify that extension has a name before trying to produce this diagnostic about operator and add an assert
in DiagnosticEngine to make sure that TypeRepr *
is not null.
Diagnostic for non-static operator declaration
is emitted here https://github.com/apple/swift/blob/master/lib/Sema/TypeCheckDecl.cpp#L679-L682. I think it might be worth adding a new diagnostic message which doesn't require a name and emit that instead if situations like this.
Ok, I will make those updates. |
…n must be 'static'" Added assert for missing a type name IsStaticRequest::evaluate now checks for ED->getExtendedTypeRepr().
Made that update. The new diagnostic message is "operator '==' declared in extension must be 'static''. How does that look? |
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.
Good catch! Could you please add a test so that we don't regress again? swift/test/decl/ext/extensions.swift
is a good spot.
I added a test in |
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.
Looks good, thank you! Have a look at https://github.com/apple/swift/blob/master/docs/Testing.md#using-litpy for how to use lit
to run the tests. --filter=
— to run a single test file.
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 have one final suggestion, the rest is up to @xedin.
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.
LGTM, thank you!
@swift-ci please smoke test |
@blueeor Looks like there are test failures. |
ok, I will look at that. |
The test fails for swift 4: I am assuming that it's working correctly for swift 5. I don't know how to set the error test in extensions.swift to only be for swift 5? |
Why does it fail for Swift 4 and not 5? |
I was mistaken. This doesn't have anything to do with swift language 4 or 5. This test is running swiftc with different options vs when xcode runs swift. With the default options on swift, this diagnosis message doesn't appear. I haven't yet figured out which swift option will make this diagnosis message appear (a pointer in the right direction would help me). The other question is would I need to put this test in it's own file and add a test that runs swiftc with the correct options? Or is there already a test that runs swift with the same options that XCode would use? |
@blueeor I think it would be fine to add a new test file with particular set of flags in RUN which reproduce this problem, you can use SR number as a file name, we do that in test-suite already. |
The code surrounding the emission of the error is not showing any dependence on an invocation flag, and the diagnostic does appear with a proper extension; it has to be something else. |
@blueeor From the stack-trace seems like the crash appears when trying to index symbols ( Edit: |
OK, so in between recent snapshots and the Xcode 11.3 release something happened that caused us to completely skip validation of members inside these anonymous extensions, which is why the error is not emitted normally in this case. We either have to fix that or hit the code path by using the appropriate command to emit index data (@LucianoPAlmeida pointed out the right one). |
@LucianoPAlmeida Thanks. I will update the test with that or I guess make a new test for this. @AnthonyLatsis It sounds like you are saying there is a larger bug at play here? |
I updated the tests and it passes for me now. I pushed the commit. Will the ci system pick this up or does it need a prompt to run again? |
//===--- Test that we don't crash when validating members inside an extension with no type name. | ||
extension { // expected-error {{expected type name in extension declaration}} | ||
static func ==(lhs: Foo, rhs: Foo) -> Bool {} // expected-error {{operator '==' declared in extension must be 'static'}} | ||
} |
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 we should move the test to test/Index
now that we use this command.
Also, since the test is somewhat alienated, can you name it after the SR to provide more context? This will make it easier to move back to decl/ext
once we fix the validation issue.
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.
Oh no, the crash is guarded, but the expected-error
checks here will have no effect. The only way to test that your error is actually there is to CHECK:
for it in the command output. That's a pretty dirty workaround, so let's wait for what Pavel has to say.
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 renamed the the test file to SR-12460.swift.
I don't understand your comment on CHECK:, the test seems to work correctly with those compile options? What I am missing?
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 don't understand your comment on CHECK:, the test seems to work correctly with those compile options? What I am missing?
The test will still pass if you mess up the expected errors. You need %target-typecheck-verify-swift
for the expected-error
check to take effect, but the error you want is only emitted as a byproduct of the %target-swift-ide-test -print-indexed-symbols
output.
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 don’t think typecheck-verify command is really necessary here, this output could be verified with FileCheck. I’ll make some experiments tomorrow and let you know.
Here is the test-case we can use for this issue, let's have it as
|
@xedin I updated the test file with those changes. |
@swift-ci please smoke test |
Thank you, @blueeor! Please don't forget to resolve associated SR. |
Print an empty string for the missing type.
Resolves SR-12460
Given this swift file:
And the swift arguments that XCode uses to compile swift.
Produce this output:
This line in bold has the fixed result. It will refer to the missing type as ''.
Before this fix, the compiler would crash when producing that line.