on master help sign in
Merge pull request #1358 from elm-lang/dev
716f653Evan Czaplicki
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright (c) 2012-2015, Evan Czaplicki
1+Copyright (c) 2012-2016, Evan Czaplicki
2
2
3All rights reserved.
3All rights reserved.
4
4
README.md+3−3
@@ -1,13 +1,13 @@
1Learn about the Elm programming language at [elm-lang.org](http://elm-lang.org/).
1Learn about the Elm programming language at [elm-lang.org](http://elm-lang.org/).
2
2
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)
4
4
5## Install
5## Install
6
6
7Follow [these instructions][installer] to use Elm on your machine. Be sure to use
7Follow [these instructions][installer] to use Elm on your machine. Be sure to use
8the platform specific installers if you are on Mac or Windows. It's way easier!
8the platform specific installers if you are on Mac or Windows. It's way easier!
9
9
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
11
11
12## Build from source / Contribute
12## Build from source / Contribute
13
13
@@ -22,4 +22,4 @@ how the script works and what your workflow will be like.
22If you are stuck, email
22If you are stuck, email
23[the list](https://groups.google.com/forum/?fromgroups#!forum/elm-discuss)
23[the list](https://groups.google.com/forum/?fromgroups#!forum/elm-discuss)
24or ask a question in the
24or 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 =
73 <* checkPortType (makeError region name) incomingType
73 <* checkPortType (makeError region name) incomingType
74
74
75 _ ->
75 _ ->
76− Result.throw region (error "TODO - bad overall type")
76+ Result.throw region (Error.BadPort name rootType)
77
77
78
78
79makeError :: R.Region -> String -> T.Canonical -> Maybe String -> A.Located Error.Error
79makeError :: R.Region -> String -> T.Canonical -> Maybe String -> A.Located Error.Error
src/Parse/Pattern.hs+20−17
@@ -18,23 +18,21 @@ basic =
18 addLocation $
18 addLocation $
19 choice
19 choice
20 [ char '_' >> return P.Anything
20 [ char '_' >> return P.Anything
21− , stringToPattern <$> var
21+ , P.Var <$> lowVar
22+ , chunksToPatterns <$> dotSep1 capVar
22 , P.Literal <$> Literal.literal
23 , P.Literal <$> Literal.literal
23 ]
24 ]
24 where
25 where
25− stringToPattern str =
26+ chunksToPatterns chunks =
26− case str of
27+ case List.intercalate "." chunks of
27− "True" ->
28+ "True" ->
28− P.Literal (L.Boolean True)
29+ P.Literal (L.Boolean True)
29
30
30− "False" ->
31+ "False" ->
31− P.Literal (L.Boolean False)
32+ P.Literal (L.Boolean False)
32
33
33− c:_ | isUpper c ->
34+ name ->
34− P.Data (Var.Raw str) []
35+ P.Data (Var.Raw name) []
35−
36− _ ->
37− P.Var str
38
36
39
37
40asPattern :: IParser P.Raw -> IParser P.Raw
38asPattern :: IParser P.Raw -> IParser P.Raw
@@ -94,11 +92,16 @@ term =
94patternConstructor :: IParser P.Raw
92patternConstructor :: IParser P.Raw
95patternConstructor =
93patternConstructor =
96 addLocation $
94 addLocation $
97− do v <- List.intercalate "." <$> dotSep1 capVar
95+ do name <- List.intercalate "." <$> dotSep1 capVar
98− case v of
96+ case name of
97+ "True" ->
99− "True" -> return $ P.Literal (L.Boolean True)
98+ return $ P.Literal (L.Boolean True)
99+
100+ "False" ->
100− "False" -> return $ P.Literal (L.Boolean False)
101+ return $ P.Literal (L.Boolean False)
102+
103+ _ ->
101− _ -> P.Data (Var.Raw v) <$> spacePrefix term
104+ P.Data (Var.Raw name) <$> spacePrefix term
102
105
103
106
104expr :: IParser P.Raw
107expr :: IParser P.Raw
src/Reporting/Error/Canonicalize.hs+19
@@ -23,6 +23,7 @@ data Error
23 | Export String [String]
23 | Export String [String]
24 | DuplicateExport String
24 | DuplicateExport String
25 | Port PortError
25 | Port PortError
26+ | BadPort String Type.Canonical
26
27
27
28
28
29
@@ -242,6 +243,21 @@ toReport localizer err =
242 ]
243 ]
243 )
244 )
244
245
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+
245
261
246argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
262argMismatchReport :: String -> Var.Canonical -> Int -> Int -> Report.Report
247argMismatchReport kind var expected actual =
263argMismatchReport kind var expected actual =
@@ -288,6 +304,9 @@ extractSuggestions err =
288 Port _ ->
304 Port _ ->
289 Nothing
305 Nothing
290
306
307+ BadPort _ _ ->
308+ Nothing
309+
291
310
292unsafePromote :: Type.Raw -> Type.Canonical
311unsafePromote :: Type.Raw -> Type.Canonical
293unsafePromote (A.A _ rawType) =
312unsafePromote (A.A _ rawType) =
src/Reporting/Error/Syntax.hs+19−3
@@ -28,6 +28,8 @@ data Error
28
28
29 | InfixDuplicate String
29 | InfixDuplicate String
30 | TypeWithoutDefinition String
30 | TypeWithoutDefinition String
31+
32+ | DuplicateArgument String String
31 | DuplicateFieldName String
33 | DuplicateFieldName String
32 | DuplicateValueDeclaration String
34 | DuplicateValueDeclaration String
33 | DuplicateTypeDeclaration String
35 | DuplicateTypeDeclaration String
@@ -135,7 +137,7 @@ toReport _localizer err =
135 "If you just wanted a normal module, change the keywords `effect module`\
137 "If you just wanted a normal module, change the keywords `effect module`\
136 \ to `module` and you should be all set. If you want a proper effect module,\
138 \ to `module` and you should be all set. If you want a proper effect module,\
137 \ you need to specify your commands and/or subscriptions. Read more about this\
139 \ 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/>"
139 )
141 )
140
142
141 MissingManagerOnEffectModule name ->
143 MissingManagerOnEffectModule name ->
@@ -147,7 +149,7 @@ toReport _localizer err =
147 "There is a small set of top-level functions and values that must be defined\
149 "There is a small set of top-level functions and values that must be defined\
148 \ in any complete effect module. The best thing is probably to just read more\
150 \ in any complete effect module. The best thing is probably to just read more\
149 \ about effect modules here:\
151 \ about effect modules here:\
150− \ <TODO> (please forgive me if I forgot to fill this in!)"
152+ \ <http://guide.elm-lang.org/effect_managers/>"
151 )
153 )
152
154
153 UnexpectedPort name ->
155 UnexpectedPort name ->
@@ -184,6 +186,20 @@ toReport _localizer err =
184 ++ " " ++ valueName ++ " = 42"
186 ++ " " ++ valueName ++ " = 42"
185 )
187 )
186
188
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+
187 DuplicateFieldName name ->
203 DuplicateFieldName name ->
188 Report.report
204 Report.report
189 "DUPLICATE FIELD"
205 "DUPLICATE FIELD"
@@ -282,7 +298,7 @@ unboundTypeVars declKind typeName givenVars unboundVars =
282 , Help.reflowParagraph $
298 , Help.reflowParagraph $
283 "Here's why. Imagine one `" ++ typeName ++ "` where `" ++ head unboundVars ++
299 "Here's why. Imagine one `" ++ typeName ++ "` where `" ++ head unboundVars ++
284 "` is an Int and another where it is a Bool. When we explicitly list the type\
300 "` 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."
286 ]
302 ]
287 )
303 )
288
304
src/Reporting/Error/Type.hs+6−5
@@ -458,7 +458,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
458 ( cmpHint
458 ( cmpHint
459 ("Your `" ++ name ++ "` function has this type:")
459 ("Your `" ++ name ++ "` function has this type:")
460 "But it needs to have a type like this:"
460 "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/>"
462 ]
463 ]
463 )
464 )
464
465
@@ -471,8 +472,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
471 ( cmpHint
472 ( cmpHint
472 "The state created by `init` has this type:"
473 "The state created by `init` has this type:"
473 ("But `" ++ name ++ "` expects state of this type:")
474 ("But `" ++ name ++ "` expects state of this type:")
474− [ "Make the two state types match and you should be all set!"
475+ [ "Make the two state types match and you should be all set! More info here:\
475− , "TODO - link to overview of effect managers"
476+ \ <http://guide.elm-lang.org/effect_managers/>"
476 ]
477 ]
477 )
478 )
478
479
@@ -483,8 +484,8 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
483 ( cmpHint
484 ( cmpHint
484 "The `onEffects` function can send this type of message:"
485 "The `onEffects` function can send this type of message:"
485 "But the `onSelfMsg` function receives this type:"
486 "But the `onSelfMsg` function receives this type:"
486− [ "Make the two message types match and you should be all set!"
487+ [ "Make the two message types match and you should be all set! More info here:\
487− , "TODO - link to overview of effect managers"
488+ \ <http://guide.elm-lang.org/effect_managers/>"
488 ]
489 ]
489 )
490 )
490
491
src/Type/Unify.hs+2−2
@@ -519,8 +519,8 @@ unifyAlias context name args realVar otherContent =
519
519
520 Alias otherName otherArgs otherRealVar ->
520 Alias otherName otherArgs otherRealVar ->
521 if name == otherName then
521 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
524
524
525 else
525 else
526 subUnify context realVar otherRealVar
526 subUnify context realVar otherRealVar
src/Validate.hs+20−5
@@ -1,8 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Validate (Result, module') where
2module Validate (Result, module') where
3
3
4−import Prelude hiding (init)
5−import Control.Monad (foldM, when)
4+import Control.Monad (foldM_, when)
6import qualified Data.Map as Map
5import qualified Data.Map as Map
7import qualified Data.Maybe as Maybe
6import qualified Data.Maybe as Maybe
8import qualified Data.Set as Set
7import qualified Data.Set as Set
@@ -428,8 +427,8 @@ validateDefPattern pattern body =
428
427
429 args ->
428 args ->
430 case pattern of
429 case pattern of
431− A.A _ (Pattern.Var _) ->
430+ A.A _ (Pattern.Var funcName) ->
432− return ()
431+ checkArguments funcName args
433
432
434 _ ->
433 _ ->
435 let
434 let
@@ -439,6 +438,22 @@ validateDefPattern pattern body =
439 Result.throw (R.merge start end) (Error.BadFunctionName (length args))
438 Result.throw (R.merge start end) (Error.BadFunctionName (length args))
440
439
441
440
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+
442
457
443-- VALIDATE EXPRESSIONS
458-- VALIDATE EXPRESSIONS
444
459
@@ -509,7 +524,7 @@ expression (A.A ann sourceExpression) =
509 else
524 else
510 return (Set.insert field seenFields)
525 return (Set.insert field seenFields)
511 in
526 in
512− do _ <- foldM checkDups Set.empty fields
527+ do foldM_ checkDups Set.empty fields
513 Record <$> T.traverse second fields
528 Record <$> T.traverse second fields
514
529
515 Let defs body ->
530 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