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

The compiler is too strict when checking consumed variables in try-else blocks #862

Open
Praetonus opened this issue May 22, 2016 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Praetonus
Copy link
Member

Currently, a consumed variable in a try block can't be consumed in the associated else block, even if the variable isn't consumed in the erroring path of the try block. For example:

actor Main
  new create(env: Env) =>
    try
      partial()
      consume env
    else
      consume env
    end

    fun partial() ? => error

If we enter the else here, env wasn't consumed in the try, but the compiler says we can't use a consumed variable.

The compiler should find the last erroring operation in a try and ignore anything happening after it when checking consumed variables in the else.

@SeanTAllen
Copy link
Member

Thanks for the report @Praetonus
This is a known issue and something that is remarkably hard to get right. There are a few issues in this general family.

The "simple" solution is:

actor Main
  new create(env: Env) =>
    try
      partial()
    end
    consume env

    fun partial() ? => error

but that might not work for all cases.

@SeanTAllen SeanTAllen added help wanted Extra attention is needed enhancement New feature or request and removed complexity: major effort labels May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants