Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ fix ] Fix pattern match issue with function application in Refl #3027

Merged
merged 8 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@

* Fixed a bug that caused holes to appear unexpectedly during quotation of dependent pairs.

* Fixed a bug that caused `f` to sometimes be replaced by `fx` after matching `fx = f x`.

### Library changes

#### Prelude
Expand Down
11 changes: 10 additions & 1 deletion src/Core/Case/CaseBuilder.idr
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,16 @@ mutual

export
mkPat : {auto c : Ref Ctxt Defs} -> List Pat -> ClosedTerm -> ClosedTerm -> Core Pat
mkPat args orig (Ref fc Bound n) = pure $ PLoc fc n
-- Only match Bound if it is applied to an empty or unmatchable spine
-- The latter is needed for matching (x : Nat) -> b
mkPat args orig (Ref fc Bound n) =
if all unmatchable args
then pure $ PLoc fc n
else pure $ PUnmatchable (getLoc orig) orig
gallais marked this conversation as resolved.
Show resolved Hide resolved
where
unmatchable : Pat -> Bool
unmatchable (PUnmatchable _ _) = True
unmatchable _ = False
mkPat args orig (Ref fc (DataCon t a) n) = pure $ PCon fc n t a args
mkPat args orig (Ref fc (TyCon t a) n) = pure $ PTyCon fc n a args
mkPat args orig (Ref fc Func n)
Expand Down
2 changes: 1 addition & 1 deletion tests/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ idrisTestsTermination = MkTestPool "Termination checking" [] Nothing
idrisTestsCasetree : TestPool
idrisTestsCasetree = MkTestPool "Case tree building" [] Nothing
-- Case tree building
["casetree001", "casetree002", "casetree003"]
["casetree001", "casetree002", "casetree003", "casetree004"]

idrisTestsWarning : TestPool
idrisTestsWarning = MkTestPool "Warnings" [] Nothing
Expand Down
11 changes: 11 additions & 0 deletions tests/idris2/casetree004/LocalArgs.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Data.Vect

bar : (f : List a -> Nat) -> (xs : List a) -> Nat
bar f xs = f xs

-- Idris was putting fx@f for the first implicit (instead of fx@(f xs))
foo : (f : List a -> Nat) -> (xs : List a) -> (0 _ : fx = f xs) -> Nat
foo f xs Refl = bar f xs

blah : (xs : List a) -> Vect (foo List.length xs Refl) ()
blah xs = replicate (length xs) ()
1 change: 1 addition & 0 deletions tests/idris2/casetree004/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1/1: Building LocalArgs (LocalArgs.idr)
3 changes: 3 additions & 0 deletions tests/idris2/casetree004/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rm -rf build

$1 --no-color --console-width 0 --no-banner LocalArgs.idr --check
Loading