on master help sign in
Add test for #1090
commitbc71d832e7d49e6268c5d63bfdcdf175b7d63701 authorEvan Czaplicki <info@elm-lang.org> dateFri 9 Oct 2015, 16:25 (11 years ago) parent05a0c16
2 files changed+48
tests/test-files/good-expected-js/CodeGenBugs/Shadowing2.elm.js+23 tests/test-files/good/CodeGenBugs/Shadowing2.elm+25
tests/test-files/good-expected-js/CodeGenBugs/Shadowing2.elm.jsnew file+23
@@ -0,0 +1,23 @@
1+Elm.Main = Elm.Main || {};
2+Elm.Main.make = function (_elm) {
3+ "use strict";
4+ _elm.Main = _elm.Main || {};
5+ if (_elm.Main.values) return _elm.Main.values;
6+ var _U = Elm.Native.Utils.make(_elm);
7+ var _op = {};
8+ var Nothing = {ctor: "Nothing"};
9+ var Just = function (a) { return {ctor: "Just",_0: a};};
10+ var withDefault0 = function (maybe) {
11+ var _p0 = maybe;
12+ if (_p0.ctor === "Just") {
13+ var maybe = Just("shadow argument, but do not overwrite it in JS!");
14+ return _p0._0;
15+ } else {
16+ return 0;
17+ }
18+ };
19+ return _elm.Main.values = {_op: _op
20+ ,Just: Just
21+ ,Nothing: Nothing
22+ ,withDefault0: withDefault0};
23+};
tests/test-files/good/CodeGenBugs/Shadowing2.elmnew file+25
@@ -0,0 +1,25 @@
1+-- https://github.com/elm-lang/elm-compiler/issues/1090
2+--
3+-- The problem was shadowing a variable used in a pattern match, but then
4+-- rebinding the variable before using all the subparts. There was an issue
5+-- in which inlining of certain values let names jump into scopes where they
6+-- did not belong.
7+
8+
9+type Maybe a
10+ = Just a
11+ | Nothing
12+
13+
14+withDefault0 : Maybe Int -> Int
15+withDefault0 maybe =
16+ case maybe of
17+ Just int ->
18+ let
19+ maybe =
20+ Just "shadow argument, but do not overwrite it in JS!"
21+ in
22+ int -- should be from the `maybe` in the argument, not the shadow
23+
24+ _ ->
25+ 0