Skip to content

Commit 9cabfc2

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 (cherry picked from commit 8fd8408)
1 parent 66d6acf commit 9cabfc2

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
@@ -3143,13 +3143,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
31433143
return result;
31443144
}
31453145

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

3151-
auto *fix = RelabelArguments::create(*this, correctLabels,
3152-
getConstraintLocator(argumentLocator));
31533152
if (recordFix(fix))
31543153
return getTypeMatchFailure(argumentLocator);
31553154
}
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)