on master help sign in
Merge pull request #1178 from elm-lang/pr/1157

Allow users to provide type annotations that are too strict

commitcb0e9efce871644e256367a3282a1672f85faa8c authorEvan Czaplicki <info@elm-lang.org> dateTue 17 Nov 2015, 13:02 (11 years ago) parentfb5c30bdae8e04
5 files changed+49−8
src/Type/Unify.hs+21−8 tests/test-files/good-expected-js/Soundness/SpecificAnnotationInt.elm.js+10 tests/test-files/good-expected-js/Soundness/SpecificAnnotationNumber.elm.js+10 tests/test-files/good/Soundness/SpecificAnnotationInt.elm+4 tests/test-files/good/Soundness/SpecificAnnotationNumber.elm+4
src/Type/Unify.hs+21−8
@@ -241,10 +241,20 @@ unifyRigid context maybeSuper maybeName otherContent =
241241 return ()
242242
243243 Var Flex otherMaybeSuper _ ->
244− if maybeSuper == otherMaybeSuper then
245− merge context (Var Rigid maybeSuper maybeName)
246− else
247− mismatch context (Just (badRigid maybeName))
244+ case (maybeSuper, otherMaybeSuper) of
245+ (_, Nothing) ->
246+ merge context (Var Rigid maybeSuper maybeName)
247+
248+ (Nothing, Just _) ->
249+ mismatch context (Just (badRigid maybeName))
250+
251+ (Just super, Just otherSuper) ->
252+ case combineSupers super otherSuper of
253+ Right newSuper | newSuper == otherSuper ->
254+ merge context otherContent
255+
256+ _ ->
257+ mismatch context (Just (badRigid maybeName))
248258
249259 Var Rigid _ otherMaybeName ->
250260 mismatch context $ Just $
@@ -279,10 +289,13 @@ unifySuper context super otherContent =
279289 mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
280290
281291 Var Rigid (Just otherSuper) maybeName ->
282− if super == otherSuper then
283− merge context otherContent
284− else
285− mismatch context (Just (doubleBad (errorSuper super) (Error.Rigid maybeName)))
292+ case combineSupers super otherSuper of
293+ Right newSuper | newSuper == super ->
294+ merge context otherContent
295+
296+ _ ->
297+ mismatch context $ Just $
298+ doubleBad (errorSuper super) (Error.Rigid maybeName)
286299
287300 Var Flex Nothing _ ->
288301 merge context (Var Flex (Just super) Nothing)
tests/test-files/good-expected-js/Soundness/SpecificAnnotationInt.elm.jsnew file+10
@@ -0,0 +1,10 @@
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 px = function (x) { return "test";};
9+ return _elm.Main.values = {_op: _op,px: px};
10+};
tests/test-files/good-expected-js/Soundness/SpecificAnnotationNumber.elm.jsnew file+10
@@ -0,0 +1,10 @@
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 px = function (x) { return "test";};
9+ return _elm.Main.values = {_op: _op,px: px};
10+};
tests/test-files/good/Soundness/SpecificAnnotationInt.elmnew file+4
@@ -0,0 +1,4 @@
1+
2+px : Int -> String
3+px x =
4+ "test"
tests/test-files/good/Soundness/SpecificAnnotationNumber.elmnew file+4
@@ -0,0 +1,4 @@
1+
2+px : number -> String
3+px x =
4+ "test"