Skip to content

Commit 8e0e414

Browse files
committed
Diag: Silence argument mismatch failures in unsupported existential member accesses
1 parent b3ee4b0 commit 8e0e414

File tree

3 files changed

+11
-75
lines changed

3 files changed

+11
-75
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6264,6 +6264,16 @@ void InOutConversionFailure::fixItChangeArgumentType() const {
62646264
}
62656265

62666266
bool ArgumentMismatchFailure::diagnoseAsError() {
6267+
const auto paramType = getToType();
6268+
6269+
// If the parameter type contains an opened archetype, it's an unsupported
6270+
// existential member access; refrain from exposing type system implementation
6271+
// details in diagnostics and complaining about a parameter the user cannot
6272+
// fulfill, and let the member access failure prevail.
6273+
if (paramType->hasOpenedExistential()) {
6274+
return false;
6275+
}
6276+
62676277
if (diagnoseMisplacedMissingArgument())
62686278
return true;
62696279

@@ -6289,7 +6299,6 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
62896299
return true;
62906300

62916301
auto argType = getFromType();
6292-
auto paramType = getToType();
62936302

62946303
if (paramType->isAnyObject()) {
62956304
emitDiagnostic(diag::cannot_convert_argument_value_anyobject, argType,

test/Generics/function_defs.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func existential<T : EqualComparable, U : EqualComparable>(_ t1: T, t2: T, u: U)
3939
if t1.isEqual(eqComp) {} // expected-error{{cannot convert value of type 'EqualComparable' to expected argument type 'T'}}
4040
if eqComp.isEqual(t2) {}
4141
// expected-error@-1 {{member 'isEqual' cannot be used on value of protocol type 'EqualComparable'; use a generic constraint instead}}
42-
// expected-error@-2 {{cannot convert value of type 'T' to expected argument type 'EqualComparable'}}
4342
}
4443

4544
protocol OtherEqualComparable {

0 commit comments

Comments
 (0)