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

Case expression with Array.popFirst and redundant branches #268

Open
aramiscd opened this issue Nov 11, 2024 · 5 comments
Open

Case expression with Array.popFirst and redundant branches #268

aramiscd opened this issue Nov 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@aramiscd
Copy link

The code:

module Bug exposing ( .. )

err : Array Int -> Int
err array =
    case Array.popFirst array of
        Nothing -> 0
        Just { first = _, rest = _ } -> 0
        _ -> 0

The error:

Compiling ...gren: Map.!: given key is not an element in the map
CallStack (from HasCallStack):
  error, called at libraries/containers/containers/src/Data/Map/Internal.hs:617:17 in containers-0.6.7:Data.Map.Internal

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation
...

It compiles without the last branch. Without the first branch it also compiles. But it seems to have problems with the redundant branches. If I remove the Array.popFirst, it also compiles.

@robinheghan robinheghan added the bug Something isn't working label Nov 11, 2024
@aramiscd
Copy link
Author

It concerns Gren 0.4.5.

@aramiscd
Copy link
Author

This is fine too:

module Bug exposing ( .. )

err : Array Int -> Int
err array =
    case Array.popFirst array of
        Nothing -> 0
        Just _ -> 0
        _ -> 0

It does not compile but it gives a normal error message and is therefore not a compiler bug.

@aramiscd
Copy link
Author

I tried a little more. Only when both first and rest are free variables does it blow up.

@robinheghan
Copy link
Member

Interesting. So there's probably a bug with record patterns and exhaustiveness, then.

@robinheghan
Copy link
Member

Thank you for looking into this, @aramiscd . This is very thorough bug report :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants