Skip to content

Commit

Permalink
Print UnquoteError names rather than just name "UnquoteFailed"
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Aug 12, 2024
1 parent 0375073 commit 4f0866d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
62 changes: 38 additions & 24 deletions src/full/Agda/TypeChecking/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ errorString = \case
SolvedButOpenHoles{} -> "SolvedButOpenHoles"
IllegalInstanceVariableInPatternSynonym _ -> "IllegalInstanceVariableInPatternSynonym"
UnusedVariableInPatternSynonym _ -> "UnusedVariableInPatternSynonym"
UnquoteFailed{} -> "UnquoteFailed"
DeBruijnIndexOutOfScope{} -> "DeBruijnIndexOutOfScope"
TooFewPatternsInWithClause{} -> "TooFewPatternsInWithClause"
TooManyPatternsInWithClause{} -> "TooManyPatternsInWithClause"
Expand Down Expand Up @@ -344,6 +343,7 @@ errorString = \case
InteractionError err -> "Interaction." ++ interactionErrorString err
NicifierError err -> "Syntax." ++ declarationExceptionString err
OptionError{} -> "OptionError"
UnquoteFailed err -> "Unquote." ++ unquoteErrorString err

ghcBackendErrorString :: GHCBackendError -> String
ghcBackendErrorString = \case
Expand All @@ -361,6 +361,17 @@ interactionErrorString = \case
NoSuchInteractionPoint{} -> "NoSuchInteractionPoint"
UnexpectedWhere{} -> "UnexpectedWhere"

unquoteErrorString :: UnquoteError -> String
unquoteErrorString = \case
BadVisibility {} -> "BadVisibility"
ConInsteadOfDef {} -> "ConInsteadOfDef"
DefInsteadOfCon {} -> "DefInsteadOfCon"
NonCanonical {} -> "NonCanonical"
BlockedOnMeta {} -> "BlockedOnMeta"
PatLamWithoutClauses {} -> "PatLamWithoutClauses"
UnquotePanic {} -> "UnquotePanic"


instance PrettyTCM TCErr where
prettyTCM err = case err of
-- Gallais, 2016-05-14
Expand Down Expand Up @@ -1377,29 +1388,7 @@ instance PrettyTCM TypeError where
vcat [ prettyTCM term <?> text "was ruled out because"
, prettyTCM err ]

UnquoteFailed e -> case e of
BadVisibility msg arg -> fsep $
pwords $ "Unable to unquote the argument. It should be `" ++ msg ++ "'."

ConInsteadOfDef x def con -> fsep $
pwords ("Use " ++ con ++ " instead of " ++ def ++ " for constructor") ++
[prettyTCM x]

DefInsteadOfCon x def con -> fsep $
pwords ("Use " ++ def ++ " instead of " ++ con ++ " for non-constructor")
++ [prettyTCM x]

NonCanonical kind t ->
fwords ("Cannot unquote non-canonical " ++ kind)
$$ nest 2 (prettyTCM t)

BlockedOnMeta _ m -> fsep $
pwords $ "Unquote failed because of unsolved meta variables."

PatLamWithoutClauses _ -> fsep $
pwords "Cannot unquote pattern lambda without clauses. Use a single `absurd-clause` for absurd lambdas."

UnquotePanic err -> __IMPOSSIBLE__
UnquoteFailed e -> prettyTCM e

DeBruijnIndexOutOfScope i EmptyTel [] -> fsep $
pwords $ "de Bruijn index " ++ show i ++ " is not in scope in the empty context"
Expand Down Expand Up @@ -1818,6 +1807,31 @@ instance PrettyTCM InteractionError where

UnexpectedWhere -> fwords "`where' clauses are not supported in holes"

instance PrettyTCM UnquoteError where
prettyTCM = \case

BadVisibility msg arg -> fsep $
pwords $ "Unable to unquote the argument. It should be `" ++ msg ++ "'."

ConInsteadOfDef x def con -> fsep $
pwords ("Use " ++ con ++ " instead of " ++ def ++ " for constructor") ++
[prettyTCM x]

DefInsteadOfCon x def con -> fsep $
pwords ("Use " ++ def ++ " instead of " ++ con ++ " for non-constructor")
++ [prettyTCM x]

NonCanonical kind t ->
fwords ("Cannot unquote non-canonical " ++ kind)
$$ nest 2 (prettyTCM t)

BlockedOnMeta _ m -> fsep $
pwords $ "Unquote failed because of unsolved meta variables."

PatLamWithoutClauses _ -> fsep $
pwords "Cannot unquote pattern lambda without clauses. Use a single `absurd-clause` for absurd lambdas."

UnquotePanic err -> __IMPOSSIBLE__

notCmp :: MonadPretty m => Comparison -> m Doc
notCmp cmp = "!" <> prettyTCM cmp
Expand Down
2 changes: 1 addition & 1 deletion test/Fail/Issue1228.err
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Issue1228.agda:40,1-45: error: [UnquoteFailed]
Issue1228.agda:40,1-45: error: [Unquote.DefInsteadOfCon]
Use def instead of con for non-constructor tt
2 changes: 1 addition & 1 deletion test/Fail/Issue1228b.err
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Issue1228b.agda:40,1-45: error: [UnquoteFailed]
Issue1228b.agda:40,1-45: error: [Unquote.ConInsteadOfDef]
Use con instead of def for constructor refl
2 changes: 1 addition & 1 deletion test/Fail/Issue7326.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Issue7326.agda:13,7-12: error: [UnquoteFailed]
Issue7326.agda:13,7-12: error: [Unquote.PatLamWithoutClauses]
Cannot unquote pattern lambda without clauses. Use a single
'absurd-clause' for absurd lambdas.
when checking that the expression unquote magic has type ⊥ → ⊤
2 changes: 1 addition & 1 deletion test/Fail/PostulateMacro.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PostulateMacro.agda:15,8-19: error: [UnquoteFailed]
PostulateMacro.agda:15,8-19: error: [Unquote.NonCanonical]
Cannot unquote non-canonical type checking computation
stuck
when checking that the expression unquote not-so-good has type Nat
2 changes: 1 addition & 1 deletion test/Fail/StrangeRecursiveUnquote.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
StrangeRecursiveUnquote.agda:12,13-33: error: [UnquoteFailed]
StrangeRecursiveUnquote.agda:12,13-33: error: [Unquote.NonCanonical]
Cannot unquote non-canonical term
f n
when checking that the expression unquote (give (f n)) has type
Expand Down

0 comments on commit 4f0866d

Please sign in to comment.