Skip to content

Commit 6d9ed1d

Browse files
committed
[CSSimplify] Allow conversions between tuple element type and a placeholder
If a placeholder appears on one of the side of tuple element matching conversion, consider that conversion to be solved, because the actual error is related to the placeholder. (cherry picked from commit 1c076f0)
1 parent 0adeb61 commit 6d9ed1d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6014,6 +6014,12 @@ bool ConstraintSystem::repairFailures(
60146014
}
60156015

60166016
case ConstraintLocator::TupleElement: {
6017+
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
6018+
recordAnyTypeVarAsPotentialHole(lhs);
6019+
recordAnyTypeVarAsPotentialHole(rhs);
6020+
return true;
6021+
}
6022+
60176023
if (isExpr<ArrayExpr>(anchor) || isExpr<DictionaryExpr>(anchor)) {
60186024
// If we could record a generic arguments mismatch instead of this fix,
60196025
// don't record a ContextualMismatch here.

test/Constraints/result_builder_diags.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,3 +907,34 @@ func test_associated_values_dont_block_solver_when_unresolved() {
907907
}
908908
}
909909
}
910+
911+
func test_dependent_member_with_unresolved_base_type() {
912+
struct Wrapper<A, T: P> : P {
913+
}
914+
915+
@resultBuilder
916+
struct Builder<A> {
917+
static func buildBlock(_ value: some P) -> some P {
918+
value
919+
}
920+
}
921+
922+
func test<A, U: P>(data: KeyPath<A, [(Int, U.T)]>, // expected-note {{in call to function 'test(data:_:)'}}
923+
@Builder<U.T> _: () -> U) -> Wrapper<A, U> { fatalError() }
924+
925+
struct Value : P {
926+
typealias T = (Int, String)
927+
}
928+
929+
struct Test : P {
930+
struct T {
931+
var values: [(Int, Value.T)]
932+
}
933+
934+
var v: some P {
935+
test(data: \T.values) { // expected-error {{generic parameter 'U' could not be inferred}}
936+
Value()
937+
}
938+
}
939+
}
940+
}

test/expr/expressions.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,9 @@ func invalidDictionaryLiteral() {
748748

749749

750750
[4].joined(separator: [1])
751-
// expected-error@-1 {{cannot convert value of type 'Int' to expected element type 'String'}}
752-
// expected-error@-2 {{cannot convert value of type '[Int]' to expected argument type 'String'}}
751+
// expected-error@-1 {{no exact matches in call to instance method 'joined'}}
752+
// expected-note@-2 {{found candidate with type '(String) -> String'}}
753+
// There is one more note here - candidate requires that 'Int' conform to 'Sequence' (requirement specified as 'Self.Element' : 'Sequence') pointing to Sequence extension
753754

754755
[4].joined(separator: [[[1]]])
755756
// expected-error@-1 {{cannot convert value of type 'Int' to expected element type 'String'}}

0 commit comments

Comments
 (0)