on master help sign in
Fix #783, resolve scoping bug with shadowing in case patterns
commit6b6d7e2fc1e8a36cad03732cd23f91db13048718 authorEvan Czaplicki <info@elm-lang.org> dateSat 13 Sep 2014, 11:42 (12 years ago) parent034d52e
2 files changed+17−1
compiler/Transform/Substitute.hs+6−1 tests/libraries/Test/CodeGen.elm+11
compiler/Transform/Substitute.hs+6−1
@@ -52,7 +52,12 @@ subst old new expression =
5252 V.Local -> if x == old then new else expression
5353
5454 Case e cases ->
55− Case (f e) $ map (second f) cases
55+ Case (f e) (map substCase cases)
56+ where
57+ substCase (pattern, expr) =
58+ if Set.member old (Pattern.boundVars pattern)
59+ then (pattern, expr)
60+ else (pattern, f expr)
5661
5762 Data tag values ->
5863 Data tag (map f values)
tests/libraries/Test/CodeGen.elm+11
@@ -25,6 +25,13 @@ caseQualified =
2525 Maybe.Just x -> x
2626 Nothing -> 0
2727
28+caseScope : String
29+caseScope =
30+ case "Not this one!" of
31+ string ->
32+ case "Hi" of
33+ string -> string
34+
2835tests : Test
2936tests =
3037 let primes =
@@ -37,8 +44,12 @@ tests =
3744 [ test "let" <| assertEqual 42 letQualified
3845 , test "case" <| assertEqual 42 caseQualified
3946 ]
47+ scope =
48+ suite "Scoping"
49+ [ test "case" <| assertEqual "Hi" caseScope ]
4050 in
4151 suite "CodeGen"
4252 [ primes
4353 , qualifiedPatterns
54+ , scope
4455 ]