mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CS] Set the naming pattern in markInvalid
This normally gets populated by successful type-checking, we still want to populate it if we fail though to avoid attempting to type-check the parent statement again.
This commit is contained in:
@@ -307,6 +307,12 @@ void SyntacticElementTarget::markInvalid() const {
|
|||||||
|
|
||||||
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
|
PreWalkResult<Pattern *> walkToPatternPre(Pattern *P) override {
|
||||||
P->setType(ErrorType::get(Ctx));
|
P->setType(ErrorType::get(Ctx));
|
||||||
|
|
||||||
|
// For a named pattern, set it on the variable. This stops us from
|
||||||
|
// attempting to double-type-check variables we've already type-checked.
|
||||||
|
if (auto *NP = dyn_cast<NamedPattern>(P))
|
||||||
|
NP->getDecl()->setNamingPattern(NP);
|
||||||
|
|
||||||
return Action::Continue(P);
|
return Action::Continue(P);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
func baz(y: [Int], z: Int) -> Int {
|
func baz(y: [Int], z: Int) -> Int {
|
||||||
switch z {
|
switch z {
|
||||||
case y[let z]: // expected-error 2{{'let' binding pattern cannot appear in an expression}}
|
case y[let z]: // expected-error {{'let' binding pattern cannot appear in an expression}}
|
||||||
z
|
z
|
||||||
default:
|
default:
|
||||||
z
|
z
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ func testNonBinding5(_ x: Int, y: [Int]) {
|
|||||||
func testNonBinding6(y: [Int], z: Int) -> Int {
|
func testNonBinding6(y: [Int], z: Int) -> Int {
|
||||||
switch 0 {
|
switch 0 {
|
||||||
// We treat 'z' here as a binding, which is invalid.
|
// We treat 'z' here as a binding, which is invalid.
|
||||||
case let y[z]: // expected-error 2{{pattern variable binding cannot appear in an expression}}
|
case let y[z]: // expected-error {{pattern variable binding cannot appear in an expression}}
|
||||||
z
|
z
|
||||||
case y[z]: // This is fine
|
case y[z]: // This is fine
|
||||||
0
|
0
|
||||||
|
|||||||
Reference in New Issue
Block a user