[Diagnostics] Diagnose comparisons with '.nan' and suggest using '.isNan' instead (#33860)

* [AST] Add 'FloatingPoint' known protocol kind

* [Sema] Emit a diagnostic for comparisons with '.nan' instead of using '.isNan'

* [Sema] Update '.nan' comparison diagnostic wording

* [Sema] Explicitly check for either arguments to be '.nan' and tweak a comment

* [Test] Tweak some comments

* [Diagnostic] Change 'isNan' to 'isNaN'

* [Sema] Fix a bug where firstArg was checked twice for FloatingPoint conformance and update some comments

* [Test] Fix comments in test file

* [NFC] Add a new 'isStandardComparisonOperator' method to 'Identifier' and use it in ConstraintSystem

* [NFC] Reuse argument decl extraction code and switch over to the new 'isStandardComparisonOperator' method

* [NFC] Update conformsToKnownProtocol to accept DeclContext and use it to check for FloatingPoint conformance
This commit is contained in:
Suyash Srijan
2020-09-09 22:08:42 +01:00
committed by GitHub
parent f9c70b4044
commit 49e7c6126c
10 changed files with 191 additions and 13 deletions

View File

@@ -165,7 +165,7 @@ Type FailureDiagnostic::restoreGenericParameters(
bool FailureDiagnostic::conformsToKnownProtocol(
Type type, KnownProtocolKind protocol) const {
auto &cs = getConstraintSystem();
return constraints::conformsToKnownProtocol(cs, type, protocol);
return constraints::conformsToKnownProtocol(cs.DC, type, protocol);
}
Type RequirementFailure::getOwnerType() const {