rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Improve "is not a subtype of" error messages

Open zth opened this issue 1 year ago • 2 comments

A lot of the recent features in rescript make use of subtyping in various ways. But, the error messages around subtyping aren't great, they mostly just say that x is not a subtype of y, but not why. We should improve those.

zth avatar Jan 13 '24 14:01 zth

And the last example in the ‘Record Type Coercion’ section seems not to work.

type a = {
  name: string,

  // mandatory, but explicitly typed as option<int>
  age: option<int>,
}

type b = {
  name: string,
  // optional field
  age?: int,
}

let nameFromB = (b: b) => b.name

let a: a = {
  name: "Name",
  age: Some(35),
}

let name = nameFromB(a :> b)

Error message is just Type a is not a subtype of b.

wyw avatar Jan 15 '24 15:01 wyw

I noticed some cases where the message doesn't even show up in V11 (the compiler exits with a Not_found exception) (#6571)

mxthevs avatar Jan 16 '24 23:01 mxthevs