8000 If a match contains a nested match where one or more cases return Never, the return type of the outer match is nil · Issue #865 · inko-lang/inko · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

If a match contains a nested match where one or more cases return Never, the return type of the outer match is nil #865

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

Open
yorickpeterse opened this issue May 16, 2025 · 0 comments
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers bug Defects, unintended behaviour, etc compiler Changes related to the compiler

Comments

@yorickpeterse
Copy link
Collaborator

Please describe the bug

The compiler has a feature where if one or more case branches in a match don't return a value, the values of other case branches are also ignored. This way you can write a match where one case does something that happens to return a value while another case returns nil or breaks/returns, and you won't get a type error.

It seems that for nested match expressions this isn't handled correctly as demonstrated by the following:

fn example(value: Int) {}

type async Main {
  fn async main {
    loop {
      let num = match 10 {
        case 10 -> 1
        case 20 -> {
          match 20 {
            case _ -> break
          }
        }
        case _ -> 30
      }

      example(num)
    }
  }
}

This code should compile with num being a value of Int, but instead num is typed as Nil and thus produces the following error:

/tmp/test.inko:16:15 error(invalid-type): expected a value of type 'Int', found 'Nil'

This is not the case if the inner match is replaced with just a break, so something goes wrong when dealing with nested match expressions.

Operating system

Arch Linux

Inko version

main

@yorickpeterse yorickpeterse added accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers bug Defects, unintended behaviour, etc compiler Changes related to the compiler labels May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers bug Defects, unintended behaviour, etc compiler Changes related to the compiler
Projects
None yet
Development

No branches or pull requests

1 participant
0