Skip to content
Playground(another site)

bynk.record_spread.type_mismatch

Error A record spread's base is a different record type.

A spread, T { ...base, x: 1 }, copies the fields of base that you do not name, so the result has the base's own type. It cannot convert one record type to another, even one with the same fields, and a T that names a different type from the base's is refused. Write the base's type, or, to build a different record, give every field: Point { x: s.x, y: s.y }. A base that is not a record is bynk.record_spread.non_record_base.

Example

type Point = { x: Int, y: Int }
type Size = { x: Int, y: Int }
fn widen(s: Size) -> Size { Point { ...s, x: 1 } } // ✗ `s` is a `Size`, not a `Point`
fn widen(s: Size) -> Size { Size { ...s, x: 1 } } // ✓ the base's own type

In the Book

See also

  • The grammar rule it governs: record_spread.
  • Every code in its category, Record spread, on the diagnostic index.
  • bynk explain bynk.record_spread.type_mismatch shows the same from the installed toolchain, without a network.