on master help sign in
Merge pull request #1358 from elm-lang/dev

Bring in some fixes pointed out by folks using 0.17

commit716f65354b40d02993e0a77df71cf3064ab7efb6 authorEvan Czaplicki <info@elm-lang.org> dateWed 27 Apr 2016, 20:50 (11 years ago) parent5643770f9fabf2
10 files changed+95−37
LICENSE+1−1 README.md+3−3 src/Canonicalize/Effects.hs+1−1 src/Parse/Pattern.hs+20−17 src/Reporting/Error/Canonicalize.hs+19 src/Reporting/Error/Syntax.hs+19−3 src/Reporting/Error/Type.hs+6−5 src/Type/Unify.hs+2−2 src/Validate.hs+20−5 tests/test-files/bad/RepeatedArgument.elm+4
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2012-2015, Evan Czaplicki
1+Copyright (c) 2012-2016, Evan Czaplicki
22
33All rights reserved.
44
README.md+3−3
@@ -1,13 +1,13 @@
11Learn about the Elm programming language at [elm-lang.org](http://elm-lang.org/).
22
3−[![Build Status](https://travis-ci.org/elm-lang/elm-compiler.svg)](https://travis-ci.org/elm-lang/elm-compiler)
3+[![Build Status](https://travis-ci.org/elm-lang/elm-compiler.svg?branch=master)](https://travis-ci.org/elm-lang/elm-compiler)
44
55## Install
66
77Follow [these instructions][installer] to use Elm on your machine. Be sure to use
88the platform specific installers if you are on Mac or Windows. It's way easier!
99
10− [installer]: https://github.com/elm-lang/elm-platform/blob/master/README.md#elm-platform
10+ [installer]: https://github.com/elm-lang/elm-platform/blob/master/README.md#elm-platform
1111
1212## Build from source / Contribute
1313
@@ -22,4 +22,4 @@ how the script works and what your workflow will be like.
2222If you are stuck, email
2323[the list](https://groups.google.com/forum/?fromgroups#!forum/elm-discuss)
2424or ask a question in the
25−[#Elm IRC channel](http://webchat.freenode.net/?channels=elm).
25+[#Elm IRC channel](http://webchat.freenode.net/?channels=elm).
src/Canonicalize/Effects.hs+1−1
@@ -73,7 +73,7 @@ figureOutKind region name rootType =
7373 <* checkPortType (makeError region name) incomingType
7474
7575 _ ->
76− Result.throw region (error "TODO - bad overall type")
76+ Result.throw region (Error.BadPort name rootType)
7777
7878
7979makeError :: R.Region -> String -> T.Canonical -> Maybe String -> A.Located Error.Error
src/Parse/Pattern.hs+20−17
@@ -18,23 +18,21 @@ basic =
1818 addLocation $
1919 choice
2020 [ char '_' >> return P.Anything
21− , stringToPattern <$> var
21+ , P.Var <$> lowVar
22+ , chunksToPatterns <$> dotSep1 capVar
2223 , P.Literal <$> Literal.literal
2324 ]
2425 where
25− stringToPattern str =
26− case str of
27− "True" ->
28− P.Literal (L.Boolean True)
26+ chunksToPatterns chunks =
27+ case List.intercalate "." chunks of
28+ "True" ->
29+ P.Literal (L.Boolean True)
2930
30− "False" ->
31− P.Literal (L.Boolean False)
31+ "False" ->
32+ P.Literal (L.Boolean False)
3233
33− c:_ | isUpper c ->
34− P.Data (Var.Raw str) []
35−
36− _ ->
37− P.Var str
34+ name ->
35+ P.Data (Var.Raw name) []
3836
3937
4038asPattern :: IParser P.Raw -> IParser P.Raw
@@ -94,11 +92,16 @@ term =
9492patternConstructor :: IParser P.Raw
9593patternConstructor =
9694 addLocation $
97− do v <- List.intercalate "." <$> dotSep1 capVar
98− case v of
99− "True" -> return $ P.Literal (L.Boolean True)
100− "False" -> return $ P.Literal (L.Boolean False)
101− _ -> P.Data (Var.Raw v) <$> spacePrefix term
95+ do name <- List.intercalate "." <$> dotSep1 capVar
96+ case name of
97+ "True" ->
98+ return $ P.Literal (L.Boolean True)
99+
100+ "False" ->
101+ return $ P.Literal (L.Boolean False)
102+
103+ _ ->
104+ P.Data (Var.Raw name) <$> spacePrefix term
102105
103106
104107expr :: IParser P.Raw
src/Reporting/Error/Canonicalize.hs+19
@@ -23,6 +23,7 @@ data Error
2323 | Export String [String]
2424 | DuplicateExport String
2525 | Port PortError
26+ | BadPort String Type.Canonical
2627
2728
2829
@@ -242,6 +243,21 @@ toReport localizer err =
242243 ]
243244 )
244245
246+ BadPort name tipe ->
247+ Report.report
248+ "PORT ERROR"
249+ Nothing
250+ ("Port `" ++ name ++ "` has an invalid type."
251+ )
252+ ( Help.stack
253+ [ text ("You are saying it should be:")
254+ , indent 4 (RenderType.toDoc localizer tipe)
255+ , Help.reflowParagraph $
256+ "But you need to use the particular format described here:\
257+ \ <http://guide.elm-lang.org/effect_managers/>"
258+ ]
259+ )
260+
245261
246262argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
247263argMismatchReport kind var expected actual =
@@ -288,6 +304,9 @@ extractSuggestions err =
288304 Port _ ->
289305 Nothing
290306
307+ BadPort _ _ ->
308+ Nothing
309+
291310
292311unsafePromote :: Type.Raw -> Type.Canonical
293312unsafePromote (A.A _ rawType) =
src/Reporting/Error/Syntax.hs+19−3
@@ -28,6 +28,8 @@ data Error
2828
2929 | InfixDuplicate String
3030 | TypeWithoutDefinition String
31+
32+ | DuplicateArgument String String
3133 | DuplicateFieldName String
3234 | DuplicateValueDeclaration String
3335 | DuplicateTypeDeclaration String
@@ -135,7 +137,7 @@ toReport _localizer err =
135137 "If you just wanted a normal module, change the keywords `effect module`\
136138 \ to `module` and you should be all set. If you want a proper effect module,\
137139 \ you need to specify your commands and/or subscriptions. Read more about this\
138− \ here: <TODO> (please forgive me if I forgot to fill this in!)"
140+ \ here: <http://guide.elm-lang.org/effect_managers/>"
139141 )
140142
141143 MissingManagerOnEffectModule name ->
@@ -147,7 +149,7 @@ toReport _localizer err =
147149 "There is a small set of top-level functions and values that must be defined\
148150 \ in any complete effect module. The best thing is probably to just read more\
149151 \ about effect modules here:\
150− \ <TODO> (please forgive me if I forgot to fill this in!)"
152+ \ <http://guide.elm-lang.org/effect_managers/>"
151153 )
152154
153155 UnexpectedPort name ->
@@ -184,6 +186,20 @@ toReport _localizer err =
184186 ++ " " ++ valueName ++ " = 42"
185187 )
186188
189+ DuplicateArgument funcName argName ->
190+ Report.report
191+ "DUPLICATE ARGUMENT"
192+ Nothing
193+ ( "The name `" ++ argName
194+ ++ "` is used more than once in the arguments of `"
195+ ++ funcName ++ "`."
196+ )
197+ ( Help.reflowParagraph $
198+ "Rename things until `" ++ argName ++ "` is used only once.\
199+ \ Otherwise how can we tell which one you want when you\
200+ \ say `" ++ argName ++ "` it in the body of your function?"
201+ )
202+
187203 DuplicateFieldName name ->
188204 Report.report
189205 "DUPLICATE FIELD"
@@ -282,7 +298,7 @@ unboundTypeVars declKind typeName givenVars unboundVars =
282298 , Help.reflowParagraph $
283299 "Here's why. Imagine one `" ++ typeName ++ "` where `" ++ head unboundVars ++
284300 "` is an Int and another where it is a Bool. When we explicitly list the type\
285− \ variables, type checker can see that they are actually different types."
301+ \ variables, the type checker can see that they are actually different types."
286302 ]
287303 )
288304
src/Reporting/Error/Type.hs+6−5
@@ -458,7 +458,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
458458 ( cmpHint
459459 ("Your `" ++ name ++ "` function has this type:")
460460 "But it needs to have a type like this:"
461− [ "TODO - link to overview of effect managers"
461+ [ "You can read more about setting up effect managers properly here:\
462+ \ <http://guide.elm-lang.org/effect_managers/>"
462463 ]
463464 )
464465
@@ -471,8 +472,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
471472 ( cmpHint
472473 "The state created by `init` has this type:"
473474 ("But `" ++ name ++ "` expects state of this type:")
474− [ "Make the two state types match and you should be all set!"
475− , "TODO - link to overview of effect managers"
475+ [ "Make the two state types match and you should be all set! More info here:\
476+ \ <http://guide.elm-lang.org/effect_managers/>"
476477 ]
477478 )
478479
@@ -483,8 +484,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
483484 ( cmpHint
484485 "The `onEffects` function can send this type of message:"
485486 "But the `onSelfMsg` function receives this type:"
486− [ "Make the two message types match and you should be all set!"
487− , "TODO - link to overview of effect managers"
487+ [ "Make the two message types match and you should be all set! More info here:\
488+ \ <http://guide.elm-lang.org/effect_managers/>"
488489 ]
489490 )
490491
src/Type/Unify.hs+2−2
@@ -519,8 +519,8 @@ unifyAlias context name args realVar otherContent =
519519
520520 Alias otherName otherArgs otherRealVar ->
521521 if name == otherName then
522− do merge context otherContent
523− zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
522+ do zipWithM_ (subUnify context) (map snd args) (map snd otherArgs)
523+ merge context otherContent
524524
525525 else
526526 subUnify context realVar otherRealVar
src/Validate.hs+20−5
@@ -1,8 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22module Validate (Result, module') where
33
4−import Prelude hiding (init)
5−import Control.Monad (foldM, when)
4+import Control.Monad (foldM_, when)
65import qualified Data.Map as Map
76import qualified Data.Maybe as Maybe
87import qualified Data.Set as Set
@@ -428,8 +427,8 @@ validateDefPattern pattern body =
428427
429428 args ->
430429 case pattern of
431− A.A _ (Pattern.Var _) ->
432− return ()
430+ A.A _ (Pattern.Var funcName) ->
431+ checkArguments funcName args
433432
434433 _ ->
435434 let
@@ -439,6 +438,22 @@ validateDefPattern pattern body =
439438 Result.throw (R.merge start end) (Error.BadFunctionName (length args))
440439
441440
441+checkArguments :: String -> [Pattern.Raw] -> Result wrn ()
442+checkArguments funcName args =
443+ let
444+ vars =
445+ concatMap Pattern.boundVars args
446+
447+ checkDups seenArgs (A.A region arg) =
448+ if Set.member arg seenArgs then
449+ Result.throw region (Error.DuplicateArgument funcName arg)
450+
451+ else
452+ return (Set.insert arg seenArgs)
453+ in
454+ foldM_ checkDups Set.empty vars
455+
456+
442457
443458-- VALIDATE EXPRESSIONS
444459
@@ -509,7 +524,7 @@ expression (A.A ann sourceExpression) =
509524 else
510525 return (Set.insert field seenFields)
511526 in
512− do _ <- foldM checkDups Set.empty fields
527+ do foldM_ checkDups Set.empty fields
513528 Record <$> T.traverse second fields
514529
515530 Let defs body ->
tests/test-files/bad/RepeatedArgument.elmnew file+4
@@ -0,0 +1,4 @@
1+
2+foo x x = 42
3+
4+bar x (x, y) = 42