Skip to content

Commit a779fa1

Browse files
authored
Merge pull request #12150 from slavapestov/csdiag-is-terrible-4.0
Sema: Fix a failure to emit a diagnostic [4.0]
2 parents bf85bfc + de24752 commit a779fa1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6034,11 +6034,15 @@ bool FailureDiagnosis::diagnoseArgumentGenericRequirements(
60346034

60356035
auto result = TC.checkGenericArguments(
60366036
dc, callExpr->getLoc(), fnExpr->getLoc(), AFD->getInterfaceType(),
6037-
env->getGenericSignature(), QueryTypeSubstitutionMap{substitutions},
6037+
env->getGenericSignature(), substitutionFn,
60386038
LookUpConformanceInModule{dc->getParentModule()}, nullptr,
60396039
ConformanceCheckFlags::SuppressDependencyTracking, &genericReqListener);
60406040

6041-
return result != RequirementCheckResult::Success;
6041+
assert(result != RequirementCheckResult::UnsatisfiedDependency);
6042+
6043+
// Note: If result is RequirementCheckResult::SubstitutionFailure, we did
6044+
// not emit a diagnostic, so we must return false in that case.
6045+
return result == RequirementCheckResult::Failure;
60426046
}
60436047

60446048
/// When initializing Unsafe[Mutable]Pointer<T> from Unsafe[Mutable]RawPointer,

test/Constraints/diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,3 +1080,12 @@ fun_31849281(a: { !$0 }, c: [nil, 42], b: { "\($0)" })
10801080

10811081
func f_31849281(x: Int, y: Int, z: Int) {}
10821082
f_31849281(42, y: 10, x: 20) // expected-error {{argument 'x' must precede unnamed argument #1}} {{12-12=x: 20, }} {{21-28=}}
1083+
1084+
// https://bugs.swift.org/browse/SR-5934 - failure to emit diagnostic for bad
1085+
// generic constraints
1086+
func elephant<T, U>(_: T) where T : Collection, T.Element == U, T.Element : Hashable {}
1087+
// expected-note@-1 {{in call to function 'elephant'}}
1088+
1089+
func platypus<T>(a: [T]) {
1090+
_ = elephant(a) // expected-error {{generic parameter 'U' could not be inferred}}
1091+
}

0 commit comments

Comments
 (0)