Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing DU member with interface after v 4.20+ #3915

Closed
OnurGumus opened this issue Oct 1, 2024 · 3 comments
Closed

Missing DU member with interface after v 4.20+ #3915

OnurGumus opened this issue Oct 1, 2024 · 3 comments

Comments

@OnurGumus
Copy link

OnurGumus commented Oct 1, 2024

Description

After upgrading to 4.20 or 4.21 one of some DU's don't generate members

Repro code

module Test

type IItem =
    abstract member Next: int
    abstract member IsSuccess: bool

type ParseSuccess = { Next: int }

type ParseResult =
    | Success of ParseSuccess

    interface IItem with
        member this.Next =
            match this with
            | Success ps -> ps.Next

        member this.IsSuccess =
            match this with
            | Success _ -> true

With 4.19 the following js is generated

import { Union, Record } from "./fable_modules/fable-library-js.4.19.0/Types.js";
import { union_type, record_type, int32_type } from "./fable_modules/fable-library-js.4.19.0/Reflection.js";

export class ParseSuccess extends Record {
    constructor(Next) {
        super();
        this.Next = (Next | 0);
    }
}

export function ParseSuccess_$reflection() {
    return record_type("Test.ParseSuccess", [], ParseSuccess, () => [["Next", int32_type]]);
}

export class ParseResult extends Union {
    constructor(Item) {
        super();
        this.tag = 0;
        this.fields = [Item];
    }
    cases() {
        return ["Success"];
    }
    get Next() {
        const this$ = this;
        return this$.fields[0].Next | 0;
    }
    get IsSuccess() {
        return true;
    }
}

export function ParseResult_$reflection() {
    return union_type("Test.ParseResult", [], ParseResult, () => [[["Item", ParseSuccess_$reflection()]]]);
}

Note the this.IsSuccess member exists here but not below.

with 4.20 and 4.21 we have

import { Union, Record } from "./fable_modules/fable-library-js.4.21.0/Types.js";
import { union_type, record_type, int32_type } from "./fable_modules/fable-library-js.4.21.0/Reflection.js";

export class ParseSuccess extends Record {
    constructor(Next) {
        super();
        this.Next = (Next | 0);
    }
}

export function ParseSuccess_$reflection() {
    return record_type("Test.ParseSuccess", [], ParseSuccess, () => [["Next", int32_type]]);
}

export class ParseResult extends Union {
    constructor(Item) {
        super();
        this.tag = 0;
        this.fields = [Item];
    }
    cases() {
        return ["Success"];
    }
    get Next() {
        const this$ = this;
        return this$.fields[0].Next | 0;
    }
}

export function ParseResult_$reflection() {
    return union_type("Test.ParseResult", [], ParseResult, () => [[["Item", ParseSuccess_$reflection()]]]);
}

Repl link:

https://fable.io/repl/#?code=FDAuE8AcFMAIEl6mgW1gXmLbsCGAjAZ1ACdcBjUWFVfaE2AOWgA8qAuWASwDtQscBYmUrVa9BIQDKAV3LlohQrE74A9moA2ICDFgAFXCULRZ8xcvSwA3gJw5mbTr372AvndiewUOIePQAEqKMppUmPYAPrBmCkqwagBmBkYmsRYg9i70iRRwiMhoAO5coAAWnvY0KHQM5VyEAHSO4ZX2OCi4oORlsPXKJeVt7bDR6fGQygC0AHywk82sriNiNRL9jfDScnGWw+2d3b39sIMVK+1jOxawAPqws30kMtDAQA&html=DwCwLgtgNgfAUHUBTAhgE3gAk8CSwqbhgAOAtEgI4CuAlgG4C8A5AMID2AdmEt2QCoBPEkmaYAxlx7cWPAB5gA9OGgBuCSBQAnAM75G1MADMyADmZYcO8VtokwmHVvGMARMRI6AXIsXVOJADWAOYAdJIQigACAO5IAEYRJFy8YDqK4tQ6YOwQFFBIeNw6UQCMoQBMoQAMGVk5eUgFRWmhELScoQBWOq4wwIrWtvaWwEN2Dk4u7mCk3r7+QWER0XGJucmcqek6mmiCaLlloeUAzIN7B7ltHd29-YM2E-ADIKgYCMDx7PsSUCg6HRuFAkciSbgoDpILR9ODYbC4QRkeKGHKcTD-eJNNzsdh9AYQJEo2ZcF6Kb77eCIZSQWBwIA&css=Q

Expected and actual results

Expected:

    get IsSuccess() {
        return true;
    }

Actual: not generated

  • Operating system
  • MacOS 15
@ncave
Copy link
Collaborator

ncave commented Oct 1, 2024

@OnurGumus Look like this has to do with #3658, where union case testers are elided. In this case IsSuccessful is the same as the generated union case tester.

@OnurGumus
Copy link
Author

I see, thanks for clarification. Well I got way by removing "Is" prefix, but that's an oddly breaking change for the unfamiliar. I eave it to you to close the issue or not.

ncave added a commit to ncave/Fable that referenced this issue Oct 1, 2024
@ncave ncave mentioned this issue Oct 1, 2024
@ncave
Copy link
Collaborator

ncave commented Oct 1, 2024

@OnurGumus We need to distinguish between the interface member and the augmented union case tester.
Fixed in #3917

@ncave ncave closed this as completed in eaafed6 Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants