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

Wrong effect inferred for effectful while header #601

Open
marzipankaiser opened this issue Sep 23, 2024 · 2 comments
Open

Wrong effect inferred for effectful while header #601

marzipankaiser opened this issue Sep 23, 2024 · 2 comments
Labels
area:typer bug Something isn't working good first issue Good for newcomers

Comments

@marzipankaiser
Copy link
Contributor

The following program compiles without typer errors:

interface Foo { def foo(): Unit }

def bar(): Bool / Foo = {
  do foo()
  false
}

def fooo() = {
  while(bar() is true) {
      ()
    }
}

def main() = {
  fooo()
}

but crashes at runtime (in JS), because there is no handler for the do foo in the loop header.
The type of fooo is shown (at least via LSP) as def fooo(): Unit / {}.

Adding a handler in main generates a warning that the handler is unused (but runs fine).

@marzipankaiser marzipankaiser added bug Something isn't working area:typer labels Sep 23, 2024
@marzipankaiser
Copy link
Contributor Author

Note: I assume we just don't add the effects from the header of the while when checking in typer, so might be an easy fix.

@b-studios
Copy link
Collaborator

Yes, we just need to add guardEffs here:

Result(Context.join(bodyTpe, defaultTpe), defaultEffs ++ bodyEffs)

@jiribenes jiribenes added the good first issue Good for newcomers label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer bug Something isn't working good first issue Good for newcomers
Projects
Development

No branches or pull requests

3 participants