Skip to content

[Sema] fix ParenPattern resolution when subexpression is a NilLiteralExpr #3564

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
Jul 18, 2016
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
7 changes: 3 additions & 4 deletions lib/Sema/TypeCheckPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,9 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,

// Convert a paren expr to a pattern if it contains a pattern.
Pattern *visitParenExpr(ParenExpr *E) {
if (Pattern *subPattern = visit(E->getSubExpr()))
return new (TC.Context) ParenPattern(E->getLParenLoc(), subPattern,
E->getRParenLoc());
return nullptr;
Pattern *subPattern = getSubExprPattern(E->getSubExpr());
return new (TC.Context) ParenPattern(E->getLParenLoc(), subPattern,
E->getRParenLoc());
}

// Convert all tuples to patterns.
Expand Down
16 changes: 16 additions & 0 deletions test/Constraints/patterns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ case let x?: break
case nil: break
}

func SR2066(x: Int?) {
// nil literals should still work when wrapped in parentheses
switch x {
case (nil): break
case _?: break
}
switch x {
case ((nil)): break
case _?: break
}
switch (x, x) {
case ((nil), _): break
case (_?, _): break
}
}

// Test x???? patterns.
switch (nil as Int???) {
case let x???: print(x, terminator: "")
Expand Down