Skip to content

Commit

Permalink
improve error message for types that are not uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed May 15, 2024
1 parent 64d6d41 commit 1b3116e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/swarm-lang/Swarm/Language/Parser/Lex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Control.Monad (void)
import Data.Char (isUpper)
import Data.Containers.ListUtils (nubOrd)
import Data.Sequence qualified as Seq
import Data.Text (Text, toLower)
import Data.Text (Text)
import Data.Text qualified as T
import Swarm.Language.Parser.Core
import Swarm.Language.Syntax
Expand Down Expand Up @@ -213,7 +213,7 @@ locIdentifier isTV = uncurry LV <$> parseLocG ((lexeme . try) (p >>= check) <?>
| t `elem` reservedWords || T.toLower t `elem` reservedWords =
failT ["Reserved word", squote t, "cannot be used as a variable name"]
| isTV && T.toTitle t `elem` reservedWords =
failT ["Reserved type name", squote (T.toTitle t), "cannot be used as a type variable name; perhaps you should make the first letter uppercase?"]
failT ["Reserved type name", squote t, "cannot be used as a type variable name; perhaps you meant", squote (T.toTitle t) <> "?"]
| isTV && isUpper (T.head t) =
failT ["Type variable names must start with a lowercase letter"]
| otherwise = return t
Expand Down
2 changes: 1 addition & 1 deletion test/unit/TestLanguagePipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ testLanguagePipeline =
, " |"
, "1 | def id : int -> int = \\x. x end"
, " | ^"
, "Reserved type name 'Int' cannot be used as a type variable name"
, "Reserved type name 'int' cannot be used as a type variable name; perhaps you meant 'Int'?"
]
)
)
Expand Down

0 comments on commit 1b3116e

Please sign in to comment.