Skip to content

We did the implicit untupling but forgot to do implicit tupling. Oops. #29213

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 2 commits into from
Jan 16, 2020
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
12 changes: 9 additions & 3 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,10 @@ namespace {
// 1b. pat
// type ~ ((T1, ..., Tn)) (n >= 2)
// 2. pat ~ (P1, ..., Pm) (m >= 2)
void implicitlyUntuplePatternIfApplicable(DiagnosticEngine &DE,
void implicitlyUntuplePatternIfApplicable(ASTContext &Ctx,
Pattern *&enumElementInnerPat,
Type enumPayloadType) {
auto &DE = Ctx.Diags;
if (auto *tupleType = dyn_cast<TupleType>(enumPayloadType.getPointer())) {
if (tupleType->getNumElements() >= 2
&& enumElementInnerPat->getKind() == PatternKind::Paren) {
Expand All @@ -859,9 +860,14 @@ void implicitlyUntuplePatternIfApplicable(DiagnosticEngine &DE,
}
} else if (auto *tupleType = enumPayloadType->getAs<TupleType>()) {
if (tupleType->getNumElements() >= 2
&& enumElementInnerPat->getKind() == PatternKind::Tuple)
&& enumElementInnerPat->getKind() == PatternKind::Tuple) {
DE.diagnose(enumElementInnerPat->getLoc(),
diag::matching_many_patterns_with_tupled_assoc_value);
enumElementInnerPat =
new (Ctx) ParenPattern(enumElementInnerPat->getStartLoc(),
enumElementInnerPat,
enumElementInnerPat->getEndLoc());
}
}
}
}
Expand Down Expand Up @@ -1406,7 +1412,7 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
newSubOptions.setContext(TypeResolverContext::EnumPatternPayload);
newSubOptions |= TypeResolutionFlags::FromNonInferredPattern;

::implicitlyUntuplePatternIfApplicable(Context.Diags, sub, elementType);
::implicitlyUntuplePatternIfApplicable(Context, sub, elementType);

sub = coercePatternToType(
pattern.forSubPattern(sub, /*retainTopLevel=*/false), elementType,
Expand Down
8 changes: 8 additions & 0 deletions test/Sema/exhaustive_switch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,14 @@ enum SR11212Tests {
}
}

// rdar://problem/58578342
func sr11212_content_generic_pattern_untupled3(b: Box<((Int, Int), Int)>) -> (Int, Int, Int) {
switch b {
case let .box((x, y), z): return (x, y, z)
// expected-warning@-1 {{the enum case has a single tuple as an associated value, but there are several patterns here, implicitly tupling the patterns and trying to match that instead}}
}
}

func sr11212_content_generic_pattern_ambiguous1(b: Box<(Int, Int)>) -> (Int, Int) {
switch b {
case .box(let b_): return b_
Expand Down