Merge pull request #3270 from dunhamsteve/impossible-lam

[ parser ] Add support for impossible lambdas
This commit is contained in:
André Videla 2024-04-29 07:12:10 +09:00 committed by GitHub
commit 5d04f89c7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 2 deletions

View File

@ -46,6 +46,9 @@ This CHANGELOG describes the merged but unreleased changes. Please see [CHANGELO
environment variable adds to the "Package Search Paths." Functionally this is
not a breaking change.
* The compiler now supports `impossible` in a non-case lambda. You can now
write `\ Refl impossible`.
* The compiler now parses `~x.fun` as unquoting `x` rather than `x.fun`
and `~(f 5).fun` as unquoting `(f 5)` rather than `(f 5).fun`.

View File

@ -427,7 +427,7 @@ testsInDir :
(poolName : String) ->
{default [] requirements : List Requirement} ->
{default Nothing codegen : Codegen} ->
IO TestPool
Lazy (IO TestPool)
testsInDir dirName poolName = do
Right names <- listDir dirName
| Left e => die $ "failed to list " ++ dirName ++ ": " ++ show e

View File

@ -782,10 +782,21 @@ mutual
commit
switch <- optional (bounds $ decoratedKeyword fname "case")
case switch of
Nothing => continueLam
Nothing => continueLamImpossible <|> continueLam
Just r => continueLamCase r
where
continueLamImpossible : Rule PTerm
continueLamImpossible = do
lhs <- bounds (opExpr plhs fname indents)
end <- bounds (decoratedKeyword fname "impossible")
pure (
let fc = boundToFC fname (mergeBounds lhs end)
alt = (MkImpossible fc lhs.val)
fcCase = boundToFC fname lhs
n = MN "lcase" 0 in
(PLam fcCase top Explicit (PRef fcCase n) (PInfer fcCase) $
PCase (virtualiseFC fc) [] (PRef fcCase n) [alt]))
bindAll : List (RigCount, WithBounds PTerm, PTerm) -> PTerm -> PTerm
bindAll [] scope = scope

View File

@ -0,0 +1,2 @@
foo : 2 = 3 -> Void
foo = (\Refl impossible)

View File

@ -0,0 +1 @@
1/1: Building LambdaImpossible (LambdaImpossible.idr)

View File

@ -0,0 +1,3 @@
. ../../../testutils.sh
check LambdaImpossible.idr