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

Cases and if statements in type signatures incorrectly take first branch #243

Closed
benwr opened this issue Jun 5, 2020 · 4 comments
Closed

Comments

@benwr
Copy link

benwr commented Jun 5, 2020

I'm running Idris2 0.2.0, and experiencing a problem where branches in type signatures sometimes seem to incorrectly reduce to the first branch:

Steps to Reproduce

-- succeeds
foo : if False then Nat else Bool
foo = Z

-- fails
-- bar : if False then Nat else Bool
-- bar = False

-- succeeds
baz : case S (S Z) of { Z => Nat; S Z => Bool; _ => Nat -> Bool }
baz = Z

-- fails
-- qux : case S (S Z) of { Z => Nat; S Z => Bool; _ => Nat -> Bool }
-- qux = \case
--   _ => True

-- fails
-- qux : case S Z of { Z => Nat; S Z => Bool; _ => Nat -> Bool }
-- qux = True

(gist here)

Expected Behavior

I'd naively expect that branches in type signatures would act like branches elsewhere (reducing differently, based on their condition or match).

Observed Behavior

Case statements in type signatures seem to (often, though not always) reduce to their first branch. I also get "warning: unreachable branch" about the other branches, which makes sense if those branches can't be taken.

Weirdly, the following seems to correctly choose "Bool":

foo : case Z of { S a => Vect a Bool; _ => Bool }
@ziman
Copy link
Collaborator

ziman commented Jun 6, 2020

If I change

foo : if False then Nat else Bool
foo = Z

to

FooTy : Type
FooTy = if False then Nat else Bool

foo : FooTy
foo = Z

the definition of foo no longer typechecks.

The same for baz.

@ziman
Copy link
Collaborator

ziman commented Jun 6, 2020

I wonder if it's somehow related to #70.

@edwinb
Copy link
Collaborator

edwinb commented Jun 6, 2020

Coincidentally, I've just been fixing this one since it came up somewhere else... it's because they're at multiplicity zero and the case compiler thinks they're ignorable, which they're not.

@edwinb
Copy link
Collaborator

edwinb commented Jun 6, 2020

(It's not related to #70, by the way, just to answer that bit explicitly... that seems to be a different problem.)

@edwinb edwinb closed this as completed Jun 6, 2020
attila-lendvai pushed a commit to attila-lendvai-patches/Idris2 that referenced this issue Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants