diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 5dec0a6a1c7e4..da0997a3d3f0b 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -242,6 +242,11 @@ ValueDecl *RequirementFailure::getDeclRef() const { // associated with it directly or rather with // one of its parents. if (auto *decl = overload->choice.getDeclOrNull()) { + // If declaration is an operator let's always use + // it to produce `in reference to` diagnostics. + if (decl->isOperator()) + return decl; + auto *DC = decl->getDeclContext(); do { diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 19ae8326b8770..a4c0d6ce98a67 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -2329,6 +2329,15 @@ ConstraintSystem::matchTypesBindTypeVar( // instead of re-trying it and failing later. if (typeVar->getImpl().canBindToHole() && !type->hasTypeVariable()) return getTypeMatchSuccess(); + + // Just like in cases where both sides are dependent member types + // with resolved base that can't be simplified to a concrete type + // let's ignore this mismatch and mark affected type variable as a hole + // because something else has to be fixed already for this to happen. + if (type->is() && !type->hasTypeVariable()) { + recordPotentialHole(typeVar); + return getTypeMatchSuccess(); + } } return formUnsolvedResult(); diff --git a/test/Constraints/rdar44770297.swift b/test/Constraints/rdar44770297.swift index 9853dd1ca2f53..d3dbbf4904655 100644 --- a/test/Constraints/rdar44770297.swift +++ b/test/Constraints/rdar44770297.swift @@ -4,8 +4,11 @@ protocol P { associatedtype A } -func foo(_: () throws -> T) -> T.A? { // expected-note {{where 'T' = 'Never'}} +func foo(_: () throws -> T) -> T.A? { fatalError() } -let _ = foo() {fatalError()} & nil // expected-error {{global function 'foo' requires that 'Never' conform to 'P'}} +// TODO(diagnostics): This expression is truly ambiguous because there is no conformance between `Never` and `P` +// which means no associated type `A` and `nil` can't be an argument to any overload of `&` so we end +// up generating at least 3 fixes per overload of `&`. But we could at least point to where the problems are. +let _ = foo() {fatalError()} & nil // expected-error {{type of expression is ambiguous without more context}} diff --git a/test/Constraints/tuple.swift b/test/Constraints/tuple.swift index 258fed72d63f8..ced92529e35ec 100644 --- a/test/Constraints/tuple.swift +++ b/test/Constraints/tuple.swift @@ -181,7 +181,7 @@ variadicWithTrailingClosure(fn: +) func gcd_23700031(_ a: T, b: T) { var a = a var b = b - (a, b) = (b, a % b) // expected-error {{protocol 'BinaryInteger' requires that 'T' conform to 'BinaryInteger'}} + (a, b) = (b, a % b) // expected-error {{referencing operator function '%' on 'BinaryInteger' requires that 'T' conform to 'BinaryInteger'}} } // diff --git a/test/Generics/deduction.swift b/test/Generics/deduction.swift index 2a5ad2cfe60f7..a06278ca67b8a 100644 --- a/test/Generics/deduction.swift +++ b/test/Generics/deduction.swift @@ -247,7 +247,7 @@ protocol Addable { // expected-note {{where 'Self' = 'U'}} static func +(x: Self, y: Self) -> Self } func addAddables(_ x: T, y: T, u: U) -> T { - u + u // expected-error{{protocol 'Addable' requires that 'U' conform to 'Addable'}} + u + u // expected-error{{referencing operator function '+' on 'Addable' requires that 'U' conform to 'Addable'}} return x+y } diff --git a/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift b/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift index d29e72ce83713..b9fbfc0bc6df6 100644 --- a/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift +++ b/validation-test/compiler_crashers_2_fixed/0119-rdar33613329.swift @@ -17,7 +17,7 @@ struct M { } } -protocol P { +protocol P { // expected-note {{where 'Self' = 'M, R>'}} associatedtype A associatedtype B @@ -42,5 +42,6 @@ extension WritableKeyPath : P { struct X { var y: Int = 0 } var x = X() x ~> \X.y ≈> { a in a += 1; return 3 } -// expected-error@-1 {{unable to infer complex closure return type; add explicit type to disambiguate}} -// expected-error@-2 {{cannot convert value of type 'M, R>' to expected argument type 'WritableKeyPath<_, _>'}} +// expected-error@-1 {{referencing operator function '~>' on 'P' requires that 'M, R>' conform to 'P'}} +// expected-error@-2 {{unable to infer complex closure return type; add explicit type to disambiguate}} +// expected-error@-3 {{cannot convert value of type 'X' to expected argument type 'M, R>.A'}}