Skip to content

Commit

Permalink
Merge pull request swiftlang#3445 from CodaFi/var-pattern-baldness
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci authored Jul 11, 2016
2 parents 5164668 + 2a5c7dd commit 92e1080
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,8 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
VarPattern *foundVP = nullptr;
pattern->forEachNode([&](Pattern *P) {
if (auto *VP = dyn_cast<VarPattern>(P))
foundVP = VP;
if (VP->getSingleVar() == var)
foundVP = VP;
});

if (foundVP && !foundVP->isLet())
Expand Down
16 changes: 15 additions & 1 deletion test/decl/var/usage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ class TestClass {
}
}

enum TestEnum {
case Test(Int, Int, Int)
}

func testEnum() -> Int {
let ev = TestEnum.Test(5, 6, 7)
switch ev {
case .Test(var i, var j, var k): // expected-warning {{variable 'i' was never mutated; consider changing to 'let' constant}} {{14-17=let}}
// expected-warning@-1 {{variable 'j' was never mutated; consider changing to 'let' constant}} {{21-24=let}}
// expected-warning@-2 {{variable 'k' was never mutated; consider changing to 'let' constant}} {{28-31=let}}
return i + j + k
default:
return 0
}
}

func nestedFunction() -> Int {
var x = 42 // No warning about being never-set.
Expand Down Expand Up @@ -231,4 +246,3 @@ func test(_ a : Int?, b : Any) {

}


0 comments on commit 92e1080

Please sign in to comment.