Skip to content

Case in do block produces bad code #3466

Description

@dunhamsteve

On discord, a user reported a case where the compiler was producing scheme code that wouldn't compile. I've reduced the test case below. It appears that an internal pattern variable pat0:0 is being referenced.

Steps to Reproduce

Attempt to compile this with the scheme backend:

import Data.Vect
foo : Maybe Int
foo = do
    y <- pure 0
    if y == 0 then do
        [x] : Vect _ Int <- sequence [pure 0]
        Just x
      else Nothing   
main : IO ()
main = printLn foo

Expected Behavior

Compilation succeeds

Observed Behavior

Exception: attempt to reference unbound identifier pat0C-58-0 at line 664, char 1948 of /Users/dunham/prj/idris/scratch/build/exec/mini_app/mini.ss
Error: INTERNAL ERROR: Chez exited with return code 255

The scheme code and the case tree contain a reference to a pat0::0 variable, which is not in scope. This should be e:2. If a 1 is filled in for the _, then correct code is generated. In that case, the only change in the case tree is {e:2} in place of `({pat0::0} [])

import Data.Vect
foo : Maybe Int
foo = do
    y <- pure 0
    if y == 0 then do
        [x] : Vect 1 Int <- sequence [pure 0]
        Just x
      else Nothing   
main : IO ()
main = printLn foo

Correct code is also generated if the outer if then else is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions