Skip to content

Commit

Permalink
Be careful when comparing tuple pattern labels with tuple type labels,
Browse files Browse the repository at this point in the history
in case the tuple type has fewer elements.

<rdar://problem/21081340> SourceKit crashed while rapidly undoing: Assertion failed: (Index < Length && "Invalid index!")

Swift SVN r29082
  • Loading branch information
cwillmor committed May 27, 2015
1 parent 3b7c0d4 commit da5903f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
// the label for the tuple type being matched.
// TODO: detect and diagnose shuffling
// TODO: permit shuffling
if (!elt.getLabel().empty() &&
if (!elt.getLabel().empty() && i < tupleTy->getNumElements() &&
elt.getLabel() != tupleTy->getElement(i).getName()) {
diagnose(elt.getLabelLoc(), diag::tuple_pattern_label_mismatch,
elt.getLabel(), tupleTy->getElement(i).getName());
Expand Down
5 changes: 5 additions & 0 deletions test/decl/var/variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ func test21057425() -> (Int, Int) {
let x: Int = "not an int!", y = 0 // expected-error{{'String' is not convertible to 'Int'}}
return (x, y)
}

// rdar://problem/21081340
func test21081340() {
let (x: a, y: b): () = foo() // expected-error{{tuple pattern has the wrong length for tuple type '()'}}
}

0 comments on commit da5903f

Please sign in to comment.