Skip to content

Commit

Permalink
Merge pull request #3270 from dunhamsteve/impossible-lam
Browse files Browse the repository at this point in the history
[ parser ] Add support for impossible lambdas
  • Loading branch information
andrevidela committed Apr 28, 2024
2 parents 84ce3a6 + 7854bf4 commit 5d04f89
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_NEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
2 changes: 1 addition & 1 deletion libs/test/Test/Golden.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/Idris/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/idris2/error/perror032/LambdaImpossible.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo : 2 = 3 -> Void
foo = (\Refl impossible)
1 change: 1 addition & 0 deletions tests/idris2/error/perror032/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1/1: Building LambdaImpossible (LambdaImpossible.idr)
3 changes: 3 additions & 0 deletions tests/idris2/error/perror032/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ../../../testutils.sh

check LambdaImpossible.idr

0 comments on commit 5d04f89

Please sign in to comment.