Skip to content

[ConstraintSystem] Fix a silly crash in repairFailures. #39124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocatorPathElt::TupleType>()) {
if (!path.empty() && path.back().is<LocatorPathElt::TupleType>()) {
rhs = path.back().getAs<LocatorPathElt::TupleType>()->getType();
path.pop_back();
lhs = path.back().getAs<LocatorPathElt::TupleType>()->getType();
Expand Down
29 changes: 29 additions & 0 deletions validation-test/compiler_crashers_2_fixed/sr14894.swift
Original file line number Diff line number Diff line change
@@ -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<T> {}

protocol View {}

@resultBuilder struct Builder {
// expected-note@+1 {{where 'Content' = 'ForEach<[String], ()>'}}
static func buildBlock<Content: View>(_ content: Content) -> Content { fatalError() }
}

struct ForEach<Data, Content> where Data : RandomAccessCollection {
init<C>(_ data: Wrapper<C>, @Builder content: (Wrapper<C.Element>) -> Content) where C : MutableCollection {}
init(_ data: Data, @Builder content: @escaping (Data.Element) -> Content) {}
}