Skip to content

[Diagnostic] Fix diagnostic when checking conformance for IUO of gene… #32987

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

Merged
merged 5 commits into from
Jul 21, 2020

Conversation

srinikhil-07
Copy link
Contributor

…ric parameter

Prints TypeRepr in diagnostic if possible to throw
accurate diagnostic for IUO conformance checking
Fixes [rdar://problem/64953106]. Fixes SR-13119

The diagnostic emitted when checking conformance for IUO of generic parameter will
print TypeRepr if present to have accurate type information. This prevents
confusion in the diagnostics emitted.

Fixes [rdar://problem/64953106]. Fixes SR-13119(https://bugs.swift.org/browse/SR-13119).

…ric parameter

Prints TypeRepr in diagnostic if possible to throw
accurate diagnostic for IUO conformance checking
Fixes [rdar://problem/64953106]. Fixes SR-13119
NULL,
varDecl->getType(),
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given we're doing this in three places in this function, I think it would be a good idea to extract and reuse:

static TypeLoc getTypeLocForDiagnostics(VarDecl *VD) {
  auto varTy = VD->getType();
  if (VD->isImplicitlyUnwrappedOptional()) {
    return TypeLoc(VD->getTypeReprOrParentPatternTypeRepr(), varTy);
  }
  return TypeLoc::withoutLoc(varTy);
}

Copy link
Contributor

@CodaFi CodaFi Jul 19, 2020

Choose a reason for hiding this comment

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

I don't think this needs to be a utility. Its ideal form is four lines

TypeLoc typeLoc = {
  varDecl->getTypeReprOrParentPatternTypeRepr(),
  varDecl->getType(),
};

};
} else {
typeLoc = {
NULL,
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to conditionalize this. getTypeReprOrParentPatternTypeRepr will always get what the user wrote, if they wrote something at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CodaFi

Yes, but this is breaking nested class/struct types. Please see the test regression I have commented in the https://bugs.swift.org/browse/SR-13119. @varungandhi-apple suggested a change which I inferred to be the above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Name lookup will see the innermost name in that scope and it should just work out. As long as those fixits compile, this is not a regression and we should update those tests. I very much prefer we preserve the way the user spelled types than fully qualify them all the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, okay. I get it

Copy link
Contributor

Choose a reason for hiding this comment

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

I very much prefer we preserve the way the user spelled types than fully qualify them all the time.

I didn't realize there was a disagreement here. Should we write this down somewhere so that newer diagnostics use this style? I thought this was a regression because the original code was printing the full type.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point. I recall we have a document that tries to explain good diagnostic hygiene. And this is certainly one of those places where you have to be really careful. Because the user-provided type may not always work if you're pulling something from a different DeclContext, and the fully-qualified type may not even work when you have ambiguities caused by e.g. the module-and-type-sharing-names bug.

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

A couple of nits, then this is good to merge.

Name lookup will see the innermost name anyway and
preferred over fully qualified name. Hence the test
cases are also updated.
This commit includes better comments for easy
understanding, formatted the bug fix code with
clang-format and fixes wrong variables inadvertently
introduced.
Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks ⛵

@CodaFi
Copy link
Contributor

CodaFi commented Jul 20, 2020

@swift-ci smoke test

1 similar comment
@CodaFi
Copy link
Contributor

CodaFi commented Jul 20, 2020

@swift-ci smoke test

@LucianoPAlmeida
Copy link
Contributor

@Nikhil0487 I think we could update those tests that are failing because although they are misleading because Int does conform with codable. They probably will be removed in #32371 anyways ... I can rebase those changes there no problem :)

This commit changes diagnostic type from error type
to Int. Although this diagnostic updated is incorrect, this will
be resolved when 32371 gets pulled.
@LucianoPAlmeida
Copy link
Contributor

@swift-ci Please smoke test

@LucianoPAlmeida
Copy link
Contributor

@swift-ci Please smoke test macOS platform

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.

5 participants