on master help sign in
Merge pull request #1095 from elm-lang/pr/1093

add tests for recent inlining fixes

commit943b78719fddffaa2672069f09b369738205462c authorEvan Czaplicki <info@elm-lang.org> dateFri 9 Oct 2015, 16:46 (11 years ago) parent24e16dbbc71d83
24 files changed+137−48
tests/test-files/good-expected-js/CaseExpression3.elm.js → tests/test-files/good-expected-js/Cases/ListZip.elm.js tests/test-files/good-expected-js/CodeGenBugs/Shadowing.elm.js+27 tests/test-files/good-expected-js/CodeGenBugs/Shadowing2.elm.js+23 tests/test-files/good-expected-js/TailRecursive.elm.js → tests/test-files/good-expected-js/CodeGenBugs/TailRecursion_ListAny.elm.js+6−6 tests/test-files/good-expected-js/NoExpressions.elm.js → tests/test-files/good-expected-js/Declarations/NoDefinitions.elm.js tests/test-files/good-expected-js/Ports.elm.js → tests/test-files/good-expected-js/Declarations/Ports.elm.js tests/test-files/good-expected-js/PortsWithTypeAliases.elm.js → tests/test-files/good-expected-js/Declarations/PortsWithTypeAliases.elm.js tests/test-files/good-expected-js/Otherwise.elm.js−13 tests/test-files/good-expected-js/AliasSubstitution.elm.js → tests/test-files/good-expected-js/Records/AliasSubstitution.elm.js tests/test-files/good-expected-js/Unify/NonHomogeneousRecords.elm.js → tests/test-files/good-expected-js/Records/NonHomogeneousRecords.elm.js+8−2 tests/test-files/good-expected-js/QuotesAndComments.elm.js → tests/test-files/good-expected-js/Strings/QuotesAndComments.elm.js tests/test-files/good/CaseExpression3.elm → tests/test-files/good/Cases/ListZip.elm tests/test-files/good/CodeGenBugs/Shadowing.elm+22 tests/test-files/good/CodeGenBugs/Shadowing2.elm+25 tests/test-files/good/CodeGenBugs/TailRecursion_ListAny.elm+12 tests/test-files/good/NoExpressions.elm → tests/test-files/good/Declarations/NoDefinitions.elm tests/test-files/good/Ports.elm → tests/test-files/good/Declarations/Ports.elm tests/test-files/good/PortsWithTypeAliases.elm → tests/test-files/good/Declarations/PortsWithTypeAliases.elm tests/test-files/good/Otherwise.elm−5 tests/test-files/good/AliasSubstitution.elm → tests/test-files/good/Records/AliasSubstitution.elm tests/test-files/good/Records/NonHomogeneousRecords.elm+14 tests/test-files/good/QuotesAndComments.elm → tests/test-files/good/Strings/QuotesAndComments.elm tests/test-files/good/TailRecursive.elm−10 tests/test-files/good/Unify/NonHomogeneousRecords.elm−12
tests/test-files/good-expected-js/CaseExpression3.elm.js → tests/test-files/good-expected-js/Cases/ListZip.elm.jsrenamed

The content is the same.

tests/test-files/good-expected-js/CodeGenBugs/Shadowing.elm.jsnew file+27
@@ -0,0 +1,27 @@
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 toName = function (a) {
9+ var name = function () {
10+ var _p0 = a;
11+ if (_p0.ctor === "First") {
12+ return "True";
13+ } else {
14+ return _p0._0;
15+ }
16+ }();
17+ return name;
18+ };
19+ var Second = F2(function (a,b) {
20+ return {ctor: "Second",_0: a,_1: b};
21+ });
22+ var First = {ctor: "First"};
23+ return _elm.Main.values = {_op: _op
24+ ,First: First
25+ ,Second: Second
26+ ,toName: toName};
27+};
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-expected-js/TailRecursive.elm.js → tests/test-files/good-expected-js/CodeGenBugs/TailRecursion_ListAny.elm.jsrenamed+6−6
@@ -5,14 +5,14 @@ Elm.Main.make = function (_elm) {
55 if (_elm.Main.values) return _elm.Main.values;
66 var _U = Elm.Native.Utils.make(_elm);
77 var _op = {};
8− var any = F2(function (f,l) {
8+ var any = F2(function (isOk,list) {
99 any: while (true) {
10− var _p0 = l;
10+ var _p0 = list;
1111 if (_p0.ctor === "::") {
12− if (f(_p0._0)) return true; else {
13− var _v1 = f,_v2 = _p0._1;
14− f = _v1;
15− l = _v2;
12+ if (isOk(_p0._0)) return true; else {
13+ var _v1 = isOk,_v2 = _p0._1;
14+ isOk = _v1;
15+ list = _v2;
1616 continue any;
1717 }
1818 } else {
tests/test-files/good-expected-js/NoExpressions.elm.js → tests/test-files/good-expected-js/Declarations/NoDefinitions.elm.jsrenamed

The content is the same.

tests/test-files/good-expected-js/Ports.elm.js → tests/test-files/good-expected-js/Declarations/Ports.elm.jsrenamed

The content is the same.

tests/test-files/good-expected-js/PortsWithTypeAliases.elm.js → tests/test-files/good-expected-js/Declarations/PortsWithTypeAliases.elm.jsrenamed

The content is the same.

tests/test-files/good-expected-js/Otherwise.elm.jsdeleted−13
@@ -1,13 +0,0 @@
1−Elm.Otherwise = Elm.Otherwise || {};
2−Elm.Otherwise.make = function (_elm) {
3− "use strict";
4− _elm.Otherwise = _elm.Otherwise || {};
5− if (_elm.Otherwise.values) return _elm.Otherwise.values;
6− var _U = Elm.Native.Utils.make(_elm);
7− var _op = {};
8− var boo = false ? "Yay" : "Boo";
9− var otherwise = 3;
10− return _elm.Otherwise.values = {_op: _op
11− ,otherwise: otherwise
12− ,boo: boo};
13−};
tests/test-files/good-expected-js/AliasSubstitution.elm.js → tests/test-files/good-expected-js/Records/AliasSubstitution.elm.jsrenamed

The content is the same.

tests/test-files/good-expected-js/Unify/NonHomogeneousRecords.elm.js → tests/test-files/good-expected-js/Records/NonHomogeneousRecords.elm.jsrenamed+8−2
@@ -5,7 +5,13 @@ Elm.Main.make = function (_elm) {
55 if (_elm.Main.values) return _elm.Main.values;
66 var _U = Elm.Native.Utils.make(_elm);
77 var _op = {};
8− var f = function (t) { var y = t.y;var x = t.x;return t;};
8+ var bindFields = function (thing) {
9+ var y = thing.y;
10+ var x = thing.x;
11+ return thing;
12+ };
913 var Thing = F2(function (a,b) { return {x: a,y: b};});
10− return _elm.Main.values = {_op: _op,Thing: Thing,f: f};
14+ return _elm.Main.values = {_op: _op
15+ ,Thing: Thing
16+ ,bindFields: bindFields};
1117};
tests/test-files/good-expected-js/QuotesAndComments.elm.js → tests/test-files/good-expected-js/Strings/QuotesAndComments.elm.jsrenamed

The content is the same.

tests/test-files/good/CaseExpression3.elm → tests/test-files/good/Cases/ListZip.elmrenamed

The content is the same.

tests/test-files/good/CodeGenBugs/Shadowing.elmnew file+22
@@ -0,0 +1,22 @@
1+-- From: https://github.com/elm-lang/elm-compiler/issues/1086
2+--
3+-- Problem is that the `a` in (Second a b) shadowed the argument to `toName`,
4+-- actually overwriting the value.
5+
6+
7+type AType
8+ = First
9+ | Second String String
10+
11+
12+toName : AType -> String
13+toName a =
14+ let name =
15+ case a of
16+ First ->
17+ "True"
18+
19+ Second a b ->
20+ a
21+ in
22+ name
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
tests/test-files/good/CodeGenBugs/TailRecursion_ListAny.elmnew file+12
@@ -0,0 +1,12 @@
1+
2+any isOk list =
3+ case list of
4+ first :: rest ->
5+ if isOk first then
6+ True
7+
8+ else
9+ any isOk rest
10+
11+ _ ->
12+ False
tests/test-files/good/NoExpressions.elm → tests/test-files/good/Declarations/NoDefinitions.elmrenamed

The content is the same.

tests/test-files/good/Ports.elm → tests/test-files/good/Declarations/Ports.elmrenamed

The content is the same.

tests/test-files/good/PortsWithTypeAliases.elm → tests/test-files/good/Declarations/PortsWithTypeAliases.elmrenamed

The content is the same.

tests/test-files/good/Otherwise.elmdeleted−5
@@ -1,5 +0,0 @@
1−module Otherwise where
2−
3−otherwise = 3
4−
5−boo = if False then "Yay" else "Boo"
tests/test-files/good/AliasSubstitution.elm → tests/test-files/good/Records/AliasSubstitution.elmrenamed

The content is the same.

tests/test-files/good/Records/NonHomogeneousRecords.elmnew file+14
@@ -0,0 +1,14 @@
1+
2+type alias Thing =
3+ { x : Float
4+ , y : Float
5+ }
6+
7+
8+bindFields : Thing -> Thing
9+bindFields thing =
10+ let
11+ x = thing.x
12+ y = thing.y
13+ in
14+ thing
tests/test-files/good/QuotesAndComments.elm → tests/test-files/good/Strings/QuotesAndComments.elmrenamed

The content is the same.

tests/test-files/good/TailRecursive.elmdeleted−10
@@ -1,10 +0,0 @@
1−
2−any f l =
3− case l of
4− x :: xs ->
5− if f x then
6− True
7− else
8− any f xs
9− _ ->
10− False
tests/test-files/good/Unify/NonHomogeneousRecords.elmdeleted−12
@@ -1,12 +0,0 @@
1−
2−type alias Thing =
3− { x:Float
4− , y:Float
5− }
6−
7−
8−f : Thing -> Thing
9−f t =
10− let x = t.x
11− y = t.y
12− in t