Skip to content

Commit

Permalink
[ parser ] Add support for impossible lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
dunhamsteve committed Apr 27, 2024
1 parent 2298f88 commit b99dd05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
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`.

### Backend changes

#### RefC Backend
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 b99dd05

Please sign in to comment.