Skip to content

Incomplete logical case error #166

@brekk

Description

@brekk

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions