Skip to content

Commit c6b342a

Browse files
committed
[ fix #443 ] Disallow anything that's not a function in where blocks
1 parent b6bda02 commit c6b342a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/Agda2Hs/Compile/Function.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ compileClause'' curModule projName x ty c@Clause{..} = do
236236
let withWhereModule = case children of
237237
[] -> id
238238
(c:_) -> addWhereModule $ qnameModule c
239-
whereDecls <- withWhereModule $ compileLocal $ mapM (getConstInfo >=> compileFun' True) children
239+
whereDecls <- withWhereModule $ compileLocal $ mapM compileWhereDef children
240240

241241
let Just body = clauseBody
242242
Just (unArg -> typ) = clauseType
@@ -250,6 +250,13 @@ compileClause'' curModule projName x ty c@Clause{..} = do
250250
(Hs.Symbol{}, p : q : ps) -> Hs.InfixMatch () p x (q : ps) rhs whereBinds
251251
_ -> Hs.Match () x ps rhs whereBinds
252252
return $ Just match
253+
where
254+
compileWhereDef f = do
255+
def <- getConstInfo f
256+
case theDef def of
257+
Function{} -> compileFun' def
258+
def -> agda2hsErrorM $
259+
"Cannot compile" <+> prettyTCM f <+> "in a `where` block"
253260

254261
keepClause :: Clause -> C Bool
255262
keepClause c@Clause{..} = case (clauseBody, clauseType) of

test/Fail/Issue443.agda

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
open import Haskell.Prelude
2+
3+
module Fail.Issue443 where
4+
5+
test :
6+
test = local
7+
where postulate local :
8+
9+
{-# COMPILE AGDA2HS test #-}

test/golden/Issue443.err

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/Fail/Issue443.agda:5.1-5: error: [CustomBackendError]
2+
agda2hs: Cannot compile Fail.Issue443.local in a `where` block

0 commit comments

Comments
 (0)