Skip to content

Commit 8fd8408

Browse files
committed
[CSSimplify] If function types mismatch on labels record a contextual mismatch
`RelabelArguments` cannot possibly diagnose this issue because there are no argument lists in this case. Let's report contextual mismatch instead. Resolves: #59058
1 parent 54102ef commit 8fd8408

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,13 +3140,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
31403140
return result;
31413141
}
31423142

3143-
if (hasLabelingFailures) {
3144-
SmallVector<Identifier, 4> correctLabels;
3145-
for (const auto &param : func2Params)
3146-
correctLabels.push_back(param.getLabel());
3143+
if (hasLabelingFailures && !hasFixFor(loc)) {
3144+
ConstraintFix *fix =
3145+
loc->isLastElement<LocatorPathElt::ApplyArgToParam>()
3146+
? AllowArgumentMismatch::create(*this, func1, func2, loc)
3147+
: ContextualMismatch::create(*this, func1, func2, loc);
31473148

3148-
auto *fix = RelabelArguments::create(*this, correctLabels,
3149-
getConstraintLocator(argumentLocator));
31503149
if (recordFix(fix))
31513150
return getTypeMatchFailure(argumentLocator);
31523151
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/apple/swift/issues/59058
4+
5+
struct MPSGraphTensor { }
6+
7+
struct MPSGraph {
8+
func addition(
9+
_ primaryTensor: MPSGraphTensor,
10+
_ secondaryTensor: MPSGraphTensor,
11+
name: String?
12+
) {
13+
14+
}
15+
}
16+
17+
struct Tensor<T> {} // expected-note {{type declared here}}
18+
19+
struct _ExecutionContext {
20+
func performBinaryOp<T>(
21+
_ lhs: Tensor<T>,
22+
_ rhs: Tensor<T>,
23+
_ op: (MPSGraphTensor, MPSGraphTensor, String?) -> MPSGraphTensor
24+
) -> Tensor<T> {
25+
fatalError()
26+
}
27+
}
28+
29+
public enum _RawTFEager {
30+
public static func addV2<T>( // expected-error {{method cannot be declared public because its parameter uses an internal type}}
31+
_ x: Tensor<T>
32+
) -> Tensor<T> {
33+
return _ExecutionContext.performBinaryOp(x, x, MPSGraph.addition)
34+
// expected-error@-1 {{instance member 'performBinaryOp' cannot be used on type '_ExecutionContext'; did you mean to use a value of this type instead?}}
35+
// expected-error@-2 {{instance member 'addition' cannot be used on type 'MPSGraph'; did you mean to use a value of this type instead?}}
36+
// expected-error@-3 {{cannot convert value of type '(MPSGraphTensor, MPSGraphTensor, String?) -> ()' to expected argument type '(MPSGraphTensor, MPSGraphTensor, String?) -> MPSGraphTensor'}}
37+
}
38+
}

0 commit comments

Comments
 (0)