Skip to content

Commit

Permalink
[ fix #359 ] Do not reapply clauses of projection-like functions to t…
Browse files Browse the repository at this point in the history
…heir parameters
  • Loading branch information
jespercockx committed Sep 11, 2024
1 parent 03c9aae commit 0721934
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Agda2Hs/Compile/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ compileFun' withSig def@Defn{..} = inTopContext $ withCurrentModule m $ do
-- module parameters (see https://github.com/agda/agda2hs/issues/305).
liftTCM $ setModuleCheckpoint m

pars <- getContextArgs
-- We apply the function clause to the module parameters from the context.
-- In case of a projection-like function, the clause is already
-- (partially or fully) applied so we should not apply again
-- (see https://github.com/agda/agda2hs/issues/359)
let droppedPars = case funProjection of
Left{} -> 0
Right proj -> size $ getProjLams $ projLams proj
pars <- drop droppedPars <$> getContextArgs
reportSDoc "agda2hs.compile.type" 8 $ "Function module parameters: " <+> prettyTCM pars

reportSDoc "agda2hs.compile.type" 8 $ "Function type (before instantiation): " <+> inTopContext (prettyTCM defType)
Expand Down
2 changes: 2 additions & 0 deletions test/AllTests.agda
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Issue309
import Issue317
import ErasedPatternLambda
import CustomTuples
import ProjectionLike

{-# FOREIGN AGDA2HS
import Issue14
Expand Down Expand Up @@ -171,4 +172,5 @@ import Issue309
import Issue317
import ErasedPatternLambda
import CustomTuples
import ProjectionLike
#-}
16 changes: 16 additions & 0 deletions test/ProjectionLike.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

open import Haskell.Prelude

module _ (@0 n : Bool) where

record R : Set where
field
fld : Int
open R public

{-# COMPILE AGDA2HS R #-}

foo : R Int
foo x = fld x

{-# COMPILE AGDA2HS foo #-}
1 change: 1 addition & 0 deletions test/golden/AllTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ import Issue309
import Issue317
import ErasedPatternLambda
import CustomTuples
import ProjectionLike

0 comments on commit 0721934

Please sign in to comment.