Skip to content

Rust and Beam crash on explicit constructors with a base and then #5271

Open

Description

@MangelMaxime

An explicit constructor that has a base call and a then block crashes on Rust and Beam. .NET prints 20 1 1.

let mutable thenCalls = 0

type NBase =
    val Id: int
    new (id: int) = { Id = id * 10 }

type NChild =
    inherit NBase
    val Extra: int
    new (id: int) = { inherit NBase(id); Extra = 1 } then thenCalls <- thenCalls + 1

let nc = NChild(2)
printfn "%d %d %d" nc.Id nc.Extra thenCalls
  • Rust: Fable crashes with The lists had different lengths, raised from makeRecord in Fable2Rust.fs.
  • Beam: it compiles, then crashes at runtime with badmap in fable_utils:field_get.

Removing the then block fixes both, including with fields written out of declaration order.

Reproduced with ./build.sh quicktest rust and ./build.sh quicktest beam on 7e12c10. #5235 doesn't change these results.

On Rust, the same crash also hides the Fable error that #5235 adds for new (...) as self = { inherit NBase(id); ... } then .... The build still fails, but with the crash instead of that message.

I haven't looked into the Beam side. For Rust, a review comment on #5235 points at the constructor handling in Fable2Rust.fs, which only inserts the base field for Sequential(baseCall, NewRecord(...)). I haven't confirmed that's the cause.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    beamErlang/Beam targetbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions