madlib icon indicating copy to clipboard operation
madlib copied to clipboard

Incomplete logical case error

Open brekk opened this issue 1 year ago • 0 comments

Given the following code:

conditions = (x) => {
  return if (x < 5) {
    "a"
  } else if (x >= 5 && x < 10) {
    if (x == 7 || x == 9) {
      "b1"
    } else {
      "b"
    }
  } else if (x < 15) {
    "c"
  }
}

👆🏽 Currently this yells as a Type Error pointing at "c":

[error]: Type error
     ╭──▶ /madness/examples/src/Temp.mad@22:5-22:8
     │
  22 │     "c"
     •     ┬──
     •     ╰╸ expected:
     •          String
     •
     •        but found:
     •          {}
     •
─────╯

But I think this error is misleading, because really what the compiler is saying is that this is an incomplete logical case, e.g.

conditions = (x) => {
  return if (x < 5) {
    "a"
  } else if (x >= 5 && x < 10) {
    if (x == 7 || x == 9) {
      "b1"
    } else {
      "b"
    }
  } else if (x < 15) {
    "c"
  } else {
    "d"
  }
}

It would be helpful if the compiler said something closer to "Logically incomplete condition, there is a case which isn't yet accounted for"

brekk avatar Apr 22 '24 21:04 brekk