Skip to content

Commit 901cbde

Browse files
authored
Merge pull request #12149 from slavapestov/csdiag-is-terrible
Sema: Fix a failure to emit a diagnostic
2 parents 004c823 + 044af75 commit 901cbde

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

lib/Sema/CSDiag.cpp

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

62156215
auto result = TC.checkGenericArguments(
62166216
dc, callExpr->getLoc(), fnExpr->getLoc(), AFD->getInterfaceType(),
6217-
env->getGenericSignature(), QueryTypeSubstitutionMap{substitutions},
6217+
env->getGenericSignature(), substitutionFn,
62186218
LookUpConformanceInModule{dc->getParentModule()}, nullptr,
62196219
ConformanceCheckFlags::SuppressDependencyTracking, &genericReqListener);
62206220

6221-
return result != RequirementCheckResult::Success;
6221+
assert(result != RequirementCheckResult::UnsatisfiedDependency);
6222+
6223+
// Note: If result is RequirementCheckResult::SubstitutionFailure, we did
6224+
// not emit a diagnostic, so we must return false in that case.
6225+
return result == RequirementCheckResult::Failure;
62226226
}
62236227

62246228
/// 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
@@ -1102,3 +1102,12 @@ func rdar17170728() {
11021102
// expected-error@-1 {{type of expression is ambiguous without more context}}
11031103
}
11041104
}
1105+
1106+
// https://bugs.swift.org/browse/SR-5934 - failure to emit diagnostic for bad
1107+
// generic constraints
1108+
func elephant<T, U>(_: T) where T : Collection, T.Element == U, T.Element : Hashable {}
1109+
// expected-note@-1 {{in call to function 'elephant'}}
1110+
1111+
func platypus<T>(a: [T]) {
1112+
_ = elephant(a) // expected-error {{generic parameter 'U' could not be inferred}}
1113+
}

validation-test/compiler_crashers_2/sr-5836.swift renamed to validation-test/compiler_crashers_2_fixed/sr-5836.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// RUN: not --crash %target-typecheck-verify-swift
2-
// REQUIRES: asserts
1+
// RUN: not %target-typecheck-verify-swift
32

43
extension Dictionary {
54
func doSomething<T>() -> [T : Value] {

0 commit comments

Comments
 (0)