agda / agda

Agda is a dependently typed programming language / interactive theorem prover.

Home Page:https://wiki.portal.chalmers.se/agda/pmwiki.php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Internal error in opaque block when case splitting when just given extended lambda

oskeri opened this issue · comments

For the code below, the following sequence of commands produces an internal error on version 2.6.4 and on master:

  1. Refine the goal with λ { x → {! x !} }
  2. Case-split on x
data  : Set where
  tt : ⊤

opaque
  f : ⊤
  f = {! λ { x → {! x !} } !}

The error is

An internal error has occurred. Please report this as a bug.
Location of the error: __IMPOSSIBLE__, called at src/full\Agda\Interaction\MakeCase.hs:222:7 in Agda-2.6.5-2CGFfl0UVRq2oEiF8zwYoq:Agda.Interaction.MakeCase

Reloading between refining and case-splitting does not give an error.

The error is thrown in this function:

getClauseZipperForIP :: QName -> Int -> TCM (CaseContext, ClauseZipper)
getClauseZipperForIP f clauseNo = do
(theDef <$> getConstInfo f) >>= \case
Function{funClauses = cs, funExtLam = extlam} -> do
let (cs1,ccs2) = fromMaybe __IMPOSSIBLE__ $ splitExactlyAt clauseNo cs
(c,cs2) = fromMaybe __IMPOSSIBLE__ $ uncons ccs2
return (extlam, (cs1, c, cs2))
d -> do
reportSDoc "impossible" 10 $ vcat
[ "getClauseZipperForIP" <+> prettyTCM f <+> text (show clauseNo)
<+> "received"
, text (show d)
]
__IMPOSSIBLE__

It turns out that getConstInfo returns an AbstractDef Function{..} here, so, somehow the opacity logic does not allow unfolding of the extended lambda.
A quick fix would be to just strip the AbstractDef wrapper here, but I guess we should understand why it is returned like this and fix the underlying problem.

Having (finally! my apologies) looked at it, the issue is that the extended lambda is added to the "declares" set of the unfolding block, but not the unfolds set. That's because we only update the unfolds set at the end of scope-checking the top-level module. Fix coming up..