Skip to content

Commit c7cde3a

Browse files
authored
Merge pull request swiftlang#63004 from xedin/improve-tuple-matching-diag-in-result-builder-context
[CSSimplify] Allow conversions between tuple element type and a placeholder
2 parents b302e82 + 1c076f0 commit c7cde3a

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
@@ -6016,6 +6016,12 @@ bool ConstraintSystem::repairFailures(
60166016
}
60176017

60186018
case ConstraintLocator::TupleElement: {
6019+
if (lhs->isPlaceholder() || rhs->isPlaceholder()) {
6020+
recordAnyTypeVarAsPotentialHole(lhs);
6021+
recordAnyTypeVarAsPotentialHole(rhs);
6022+
return true;
6023+
}
6024+
60196025
if (isExpr<ArrayExpr>(anchor) || isExpr<DictionaryExpr>(anchor)) {
60206026
// If we could record a generic arguments mismatch instead of this fix,
60216027
// 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)