gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
16.7k stars 698 forks source link

Unreachable cases not always detected for ints, floats, and strings #2651

Closed shapr closed 2 months ago

shapr commented 4 months ago

Hello, I'm walking through the gleam.run tutorial and I've found what appears to be a bug. The code below does not give an error or warning about unreachable code. Perhaps this is specific to the wasm runtime, and not present in the OTP version?

import gleam/io
// import gleam/int

pub fn main() {
  let x = 3 // int.random(4)
  io.debug(x)

  let result = case x {
    // Match specific values
    0 -> "Zero"
    1 -> "One"
    _ -> "Other"
    // Match any other value
    3 -> "hi"
    4 -> "no"
  }
  io.debug(result)
}

Reordering the cases slightly does tell me there is unreachable code:

import gleam/io
import gleam/int

pub fn main() {
  let x = 3 // int.random(4)
  io.debug(x)

  let result = case x {
    // Match specific values
    _ -> "Other"
    0 -> "Zero"
    1 -> "One"
    // Match any other value
    3 -> "hi"
    4 -> "no"
  }
  io.debug(result)
}
lpil commented 4 months ago

Thank you