Skip to content

Commit

Permalink
Fix 'not a primitive type' error message (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz authored Nov 30, 2022
1 parent 3fbf9a3 commit 57a6a7e
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/Juvix/Compiler/Core/Translation/FromSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Juvix.Compiler.Core.Translation.FromSource
where

import Control.Monad.Combinators.NonEmpty qualified as NonEmpty
import Control.Monad.Fail qualified as P
import Control.Monad.Trans.Class (lift)
import Data.HashMap.Strict qualified as HashMap
import Data.List.NonEmpty (fromList)
Expand Down Expand Up @@ -558,7 +557,6 @@ atom varsNum vars =
<|> exprConstString
<|> exprUniverse
<|> exprDynamic
<|> exprTypePrim
<|> exprPi varsNum vars
<|> exprLambda varsNum vars
<|> exprLetrecMany varsNum vars
Expand Down Expand Up @@ -589,14 +587,6 @@ exprUniverse = do
exprDynamic :: ParsecS r Type
exprDynamic = kw kwAny $> mkDynamic'

exprTypePrim :: ParsecS r Type
exprTypePrim = P.try $ do
txt <- identifier
case txt of
"int" -> return mkTypeInteger'
"string" -> return mkTypeString'
_ -> P.fail "not a primitive type"

parseLocalName ::
forall r.
Members '[InfoTableBuilder, NameIdGen] r =>
Expand Down Expand Up @@ -940,21 +930,24 @@ exprNamed ::
exprNamed varsNum vars = do
off <- P.getOffset
(txt, i) <- identifierL
case HashMap.lookup txt vars of
Just k -> do
name <- lift $ freshName KNameLocal txt i
return $ mkVar (Info.singleton (NameInfo name)) (varsNum - k - 1)
Nothing -> do
r <- lift (getIdent txt)
case r of
Just (IdentFun sym) -> do
name <- lift $ freshName KNameFunction txt i
return $ mkIdent (Info.singleton (NameInfo name)) sym
Just (IdentInd sym) -> do
name <- lift $ freshName KNameConstructor txt i
return $ mkTypeConstr (Info.singleton (NameInfo name)) sym []
Just (IdentConstr tag) -> do
name <- lift $ freshName KNameConstructor txt i
return $ mkConstr (Info.singleton (NameInfo name)) tag []
Nothing ->
parseFailure off ("undeclared identifier: " ++ fromText txt)
case txt of
"int" -> return mkTypeInteger'
"string" -> return mkTypeString'
_ -> case HashMap.lookup txt vars of
Just k -> do
name <- lift $ freshName KNameLocal txt i
return $ mkVar (Info.singleton (NameInfo name)) (varsNum - k - 1)
Nothing -> do
r <- lift (getIdent txt)
case r of
Just (IdentFun sym) -> do
name <- lift $ freshName KNameFunction txt i
return $ mkIdent (Info.singleton (NameInfo name)) sym
Just (IdentInd sym) -> do
name <- lift $ freshName KNameConstructor txt i
return $ mkTypeConstr (Info.singleton (NameInfo name)) sym []
Just (IdentConstr tag) -> do
name <- lift $ freshName KNameConstructor txt i
return $ mkConstr (Info.singleton (NameInfo name)) tag []
Nothing ->
parseFailure off ("undeclared identifier: " ++ fromText txt)

0 comments on commit 57a6a7e

Please sign in to comment.