Skip to content

Latest Fable fails to compile Fable.React #3658

@kerams

Description

@kerams

Description

.\src\Client\fable_modules\Fable.React.9.3.0\Fable.React.Props.fs(43,5): (43,12) error FABLE: Cannot test erased union cases

This is because the bundled FCS contains dotnet/fsharp#16341, and Fable tries to create case tester functions for every case.

export function HTMLAttr__get_IsHref(this$, unitArg) {
    if (this$.tag === 0) {
        return true;
    }
    else {
        return false;
    }
}

export function HTMLAttr__get_IsCustom(this$, unitArg) {
    if (this$.tag === 1) {
        return true;
    }
    else {
        return false;
    }
}

export const x = HTMLAttr__get_IsCustom(new HTMLAttr(1, []));

for

type HTMLAttr =
    | Href of string
    | Custom

let x = Custom.IsCustom

Adding [<Fable.Core.Erase>] to Href or Custom introduces a compiler error.

I suggest Fable is adjusted to recognize the newly exposed case testers and to emit tag comparisons at call sites instead of creating properties. That way compilation will only fail when trying to use a case tester on an erased case.

export const x = (new HTMLAttr(1, [])).tag === 1;

Repro code

https://fable.io/repl/#?code=C4TwDgpgBAEgKgWQDIEFjAE5QLwCgoFQA+UAFAFRQDaAPAGICGARgDYQB0AwgPYYcCiGBgGcIAPgC6UcgEoYfAGZRuS4ZgCWAOwDm+QiU4BXNdwC2uXG2BQAHjihGTp9gElhj4GaA&html=Q&css=Q

Related information

  • Fable version: 4.8.1

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