Skip to content

wrap is read as a variable when compiling `with' blocks #664

@developedby

Description

@developedby

Reproducing the behavior

This excerpt:

def main():
  with IO:
    x <- wrap(1)
    return wrap(wrap(2))

Should be desugaring to

(main) = (IO/bind (IO/wrap 1) λa (a λ* (IO/wrap (IO/wrap 2))))

Instead it desugars into

(main) = (IO/bind (IO/wrap 1) λa (a λb let {c d} = b; λ* (c (d 2)) IO/wrap))

wrap is seen as a free variable, so it gets applied in a deferred way as well as duplicated if it's used more than once.

We need to first substitute the wrap and only then desugar the bind.

System Settings

Bend commit 270f39c

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompilationCompilation of terms and functions to HVM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions