diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 98b3432b02157..64493780acd5f 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -4761,7 +4761,7 @@ bool ConstraintSystem::repairFailures( path.pop_back(); // Drop the tuple type path elements too, but extract each tuple type first. - if (path.back().is()) { + if (!path.empty() && path.back().is()) { rhs = path.back().getAs()->getType(); path.pop_back(); lhs = path.back().getAs()->getType(); diff --git a/validation-test/compiler_crashers_2_fixed/sr14894.swift b/validation-test/compiler_crashers_2_fixed/sr14894.swift new file mode 100644 index 0000000000000..084134a05addb --- /dev/null +++ b/validation-test/compiler_crashers_2_fixed/sr14894.swift @@ -0,0 +1,29 @@ +// RUN: %target-swift-frontend -typecheck -verify %s + +struct S { + private let data: [[String]] + private func f() {} + + func test() { + // expected-error@+1 {{static method 'buildBlock' requires that 'ForEach<[String], ()>' conform to 'View'}} + ForEach(data) { group in + ForEach(group) { month in + self.f() + } + } + } +} + +struct Wrapper {} + +protocol View {} + +@resultBuilder struct Builder { + // expected-note@+1 {{where 'Content' = 'ForEach<[String], ()>'}} + static func buildBlock(_ content: Content) -> Content { fatalError() } +} + +struct ForEach where Data : RandomAccessCollection { + init(_ data: Wrapper, @Builder content: (Wrapper) -> Content) where C : MutableCollection {} + init(_ data: Data, @Builder content: @escaping (Data.Element) -> Content) {} +}