Skip to content

Commit ce7751c

Browse files
authored
Merge pull request #3564 from jtbandes/jtbandes/fix-nil
2 parents 132366c + c3126e9 commit ce7751c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,9 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
385385

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

394393
// Convert all tuples to patterns.

test/Constraints/patterns.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ case let x?: break
127127
case nil: break
128128
}
129129

130+
func SR2066(x: Int?) {
131+
// nil literals should still work when wrapped in parentheses
132+
switch x {
133+
case (nil): break
134+
case _?: break
135+
}
136+
switch x {
137+
case ((nil)): break
138+
case _?: break
139+
}
140+
switch (x, x) {
141+
case ((nil), _): break
142+
case (_?, _): break
143+
}
144+
}
145+
130146
// Test x???? patterns.
131147
switch (nil as Int???) {
132148
case let x???: print(x, terminator: "")

0 commit comments

Comments
 (0)