1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00

[typecheck] Add the definition loc to microjuvix names

This is used in type errors
This commit is contained in:
Paul Cadman 2022-04-01 10:04:48 +01:00
parent 49a91c404f
commit c9b0193fb4
3 changed files with 15 additions and 6 deletions

View File

@ -18,6 +18,9 @@ indent' = indent 2
prettyT :: Text -> Doc Eann prettyT :: Text -> Doc Eann
prettyT = pretty prettyT = pretty
highlight :: Doc Eann -> Doc Eann
highlight = annotate Highlight
class PrettyError e where class PrettyError e where
ppError :: e -> Doc Eann ppError :: e -> Doc Eann
@ -58,8 +61,12 @@ instance PrettyError ExpectedFunctionType where
<> line <> indent' (ppCode (e ^. expectedFunctionTypeType)) <> line <> indent' (ppCode (e ^. expectedFunctionTypeType))
instance PrettyError TooManyPatterns where instance PrettyError TooManyPatterns where
ppError e = "Type error in the definition of" <+> ppCode (e ^. tooManyPatternsClause . clauseName) <> "." ppError e = "Type error near" <+> highlight (pretty (name ^. nameDefined))
<> line <> "The function clause:" <> line <> "In in the definition of" <+> ppCode name <+> "the function clause:"
<> line <> indent' (ppCode (e ^. tooManyPatternsClause)) <> line <> indent' (ppCode (e ^. tooManyPatternsClause))
<> line <> "matches too many patterns. It should match the following types:" <> line <> "matches too many patterns. It should match the following types:"
<> line <> indent' (hsep (ppCode <$> (e ^. tooManyPatternsTypes))) <> line <> indent' (hsep (ppCode <$> (e ^. tooManyPatternsTypes)))
where
name :: Name
name = (e ^. tooManyPatternsClause . clauseName)

View File

@ -11,6 +11,7 @@ import MiniJuvix.Syntax.ForeignBlock
import MiniJuvix.Syntax.Backends import MiniJuvix.Syntax.Backends
import MiniJuvix.Syntax.Concrete.Scoped.Name (NameId (..)) import MiniJuvix.Syntax.Concrete.Scoped.Name (NameId (..))
import MiniJuvix.Syntax.Concrete.Scoped.Name.NameKind import MiniJuvix.Syntax.Concrete.Scoped.Name.NameKind
import qualified MiniJuvix.Syntax.Concrete.Language as C
import MiniJuvix.Syntax.Concrete.Literal import MiniJuvix.Syntax.Concrete.Literal
import MiniJuvix.Syntax.Fixity import MiniJuvix.Syntax.Fixity
import Prettyprinter import Prettyprinter
@ -28,8 +29,8 @@ type InductiveName = Name
data Name = Name data Name = Name
{ _nameText :: Text, { _nameText :: Text,
_nameId :: NameId, _nameId :: NameId,
_nameKind :: NameKind _nameKind :: NameKind,
-- TODO: Add Location here so we can print out line numbers _nameDefined :: C.Interval
} }
deriving stock (Show) deriving stock (Show)

View File

@ -24,8 +24,9 @@ goSymbol :: S.Symbol -> Name
goSymbol s = goSymbol s =
Name Name
{ _nameText = S.symbolText s, { _nameText = S.symbolText s,
_nameId = S._nameId s, _nameId = s ^. S.nameId,
_nameKind = getNameKind s } _nameKind = getNameKind s,
_nameDefined = s ^. S.nameDefined}
unsupported :: Text -> a unsupported :: Text -> a
unsupported thing = error ("Abstract to MicroJuvix: Not yet supported: " <> thing) unsupported thing = error ("Abstract to MicroJuvix: Not yet supported: " <> thing)