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

[SR-10979] Add fix-it for missing operator #26258

Merged
merged 2 commits into from Jul 23, 2019

Conversation

mcichecki
Copy link
Contributor

This PR adds fix-it for operator functions when operator is not declared.

Resolves SR-10979.

Copy link
Collaborator

@harlanhaskins harlanhaskins left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks for fixing this! I have a couple of suggestions, but overall this looks goof.

lib/Sema/TypeCheckDecl.cpp Show resolved Hide resolved
insertion += operatorName.str();
insertion += " : <# Precedence Group #>\n";
TC.diagnose(FD, diag::declared_operator_without_operator_decl)
.fixItInsert(insertionLoc, insertion);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you guard this on if insertionLoc.isValid()?

Copy link
Collaborator

@theblixguy theblixguy left a comment

Choose a reason for hiding this comment

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

Just one small suggestion

// FIXME: Add Fix-It introducing an operator declaration?
TC.diagnose(FD, diag::declared_operator_without_operator_decl);
SourceLoc insertionLoc;
if (dyn_cast<SourceFile>(FD->getParent())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (dyn_cast<SourceFile>(FD->getParent())) {
if (isa<SourceFile>(FD->getParent())) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, applied.

CurContext;
CurContext = CurContext->getParent()) {
insertionLoc = CurContext->getAsDecl()->getStartLoc();
if (dyn_cast<SourceFile>(CurContext->getParent()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (dyn_cast<SourceFile>(CurContext->getParent()))
if (isa<SourceFile>(CurContext->getParent()))

@harlanhaskins
Copy link
Collaborator

@swift-ci please test

@harlanhaskins
Copy link
Collaborator

Thanks @mcichecki! And welcome to the Swift project, we really appreciate your contribution!

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.

None yet

3 participants