Skip to content

Commit

Permalink
[ fix #7029 ] Check that function does not have unsolved metas when w…
Browse files Browse the repository at this point in the history
…e add a rewrite rule to it and confluence checking is enabled
  • Loading branch information
jespercockx committed Dec 13, 2023
1 parent 8cf0bae commit de7f503
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/full/Agda/TypeChecking/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,10 @@ instance PrettyTCM TypeError where
[ prettyTCM q , " is not a legal rewrite rule, since the head symbol"
, prettyTCM f , "is not a postulate, a function, or a constructor"
]
HeadSymbolDefContainsMetas f -> hsep
[ prettyTCM q , "is not a legal rewrite rule, since the definition of the head symbol"
, prettyTCM f , "contains unsolved metavariables and confluence checking is enabled."
]
ConstructorParamsNotGeneral c vs -> vcat
[ prettyTCM q <+> text " is not a legal rewrite rule, since the constructor parameters are not fully general:"
, nest 2 $ text "Constructor: " <+> prettyTCM c
Expand Down
1 change: 1 addition & 0 deletions src/full/Agda/TypeChecking/Monad/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4736,6 +4736,7 @@ data IllegalRewriteRuleReason
| HeadSymbolIsProjection QName
| HeadSymbolIsProjectionLikeFunction QName
| HeadSymbolNotPostulateFunctionConstructor QName
| HeadSymbolDefContainsMetas QName
| ConstructorParamsNotGeneral ConHead Args
| ContainsUnsolvedMetaVariables (Set MetaId)
| BlockedOnProblems (Set ProblemId)
Expand Down
11 changes: 9 additions & 2 deletions src/full/Agda/TypeChecking/Rewriting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import Agda.Interaction.Options
import Agda.Syntax.Abstract.Name
import Agda.Syntax.Common
import Agda.Syntax.Internal as I
import Agda.Syntax.Internal.MetaVars
import Agda.Syntax.Internal.Pattern

import Agda.TypeChecking.Datatypes
import Agda.TypeChecking.Monad
Expand Down Expand Up @@ -337,10 +339,15 @@ checkRewriteRule q = do
checkAxFunOrCon :: QName -> Definition -> TCM ()
checkAxFunOrCon f def = case theDef def of
Axiom{} -> return ()
def@Function{} -> whenJust (maybeRight (funProjection def)) $ \proj ->
case projProper proj of
def@Function{} -> do
whenJust (maybeRight (funProjection def)) $ \proj -> case projProper proj of
Just{} -> typeError $ IllegalRewriteRule q (HeadSymbolIsProjection f)
Nothing -> typeError $ IllegalRewriteRule q (HeadSymbolIsProjectionLikeFunction f)
whenM (isJust . optConfluenceCheck <$> pragmaOptions) $ do
let simpleClause cl = (patternsToElims (namedClausePats cl) , clauseBody cl)
cls <- instantiateFull $ map simpleClause $ funClauses def
unless (noMetas cls) $ typeError $ IllegalRewriteRule q (HeadSymbolDefContainsMetas f)

Constructor{} -> return ()
AbstractDefn{} -> return ()
Primitive{} -> return () -- TODO: is this fine?
Expand Down
13 changes: 13 additions & 0 deletions test/Fail/Issue7029.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{-# OPTIONS --rewriting --confluence-check --with-K #-}

open import Agda.Builtin.Equality

{-# BUILTIN REWRITE _≡_ #-}

myrefl : {ℓ} {A : Set ℓ} {x : A} x ≡ x
myrefl = ?

UIP : {ℓ} {A : Set ℓ} {x : A} myrefl {ℓ} {A} {x} ≡ refl
UIP with refl myrefl = refl

{-# REWRITE UIP #-}
3 changes: 3 additions & 0 deletions test/Fail/Issue7029.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Issue7029.agda:13,1-20
UIP is not a legal rewrite rule, since the definition of the head symbol myrefl contains unsolved metavariables and confluence checking is enabled.
when checking the pragma REWRITE UIP

0 comments on commit de7f503

Please sign in to comment.