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

Override produces broken Javascript with template #3895

Open
davedawkins opened this issue Sep 20, 2024 · 2 comments
Open

Override produces broken Javascript with template #3895

davedawkins opened this issue Sep 20, 2024 · 2 comments

Comments

@davedawkins
Copy link
Contributor

Description

I have a class hierarchy that implements IAspect<'C> and overrides the Attach method. The bottom-most class(ProjectSelection) is causing Fable to generate code that fails at runtime, making reference to a non-existent method. This is caught by the example program below, and printed.

I've trimmed this down from my application code. If I remove the <'C> templating parameter, the issue goes away. That may be useful in tracking the issue down.

Bad code in class ProjectSelection:

    "OverrideIssue.AspectBase`1.Attach2B595"(owner) {
        super["OverrideIssue.AspectBase`1.Attach1505"](owner); // Attach1505 is undefined
        toConsole(printf("ProjectSelection: attach to %A"))(owner);
    }

Repro code

module OverrideIssue

type IAspect<'C> =
    abstract Attach: 'C -> unit

[<AbstractClass>]
type AspectBase<'C>( ) =

    abstract Attach: 'C -> unit
    default this.Attach (owner): unit = 
        printfn "AspectBase: attach to %A" owner

    interface IAspect<'C> with
        member __.Attach (owner): unit = __.Attach(owner)

type SelectionAspect<'Container>( ) =
    inherit AspectBase<'Container>()

    override __.Attach(owner) = 
        base.Attach(owner)
        printfn "SelectionAspect: attach to %A" owner

type ProjectSelection() =
    inherit SelectionAspect<string>()

    override __.Attach(owner) = 
        base.Attach(owner)
        printfn "ProjectSelection: attach to %A" owner

try
    (new ProjectSelection()).Attach("root")
with
| x -> printfn "Error: %s" x.Message

Fable REPL URL

https://fable.io/repl/#?code=LYewJgrgNgpgBAeQG4wE6oJZhgSQM54QwBQxALgJ4AO8OAgnjQMZkA8A5AMIB8cAvMThC4AQwBGeMqhEs4dMmRkALAFxwucALS8IAOwxlSAbVZ0JUmWU5QRBbgF1y1eA2ZkAQrZgceACjgAlPykwqLm0rLyikyq6pxaOvqGodgAZiLQZHBkShh4AHRRynC+IADuumgBanoG-HCCocJUmLpkqbpwAESuMCyeeDBqIgrFZCBwAKR0XXDllaghwhhtaOlMtL0sPrxlBkqNTXDAMMBiaHAA+peFozEl81U1SfXXt9FKpRVVpJQ0cABlGCwFgYEC6LZsLjgxQrNDcfxBAShFZKNB1SEDbzQtoiOGoBEBJZCEAodBYeBvIoxL4LJENI5CMRed7KWk-RlwFordqdLpAkFkMEQxh9MjDO5KbITaazR6LJz-AAKqBAACsxQKxcLfEjDnBUeislrQeDIaxJK0AOaE4lzMmYbBXG7Uz7y+n60LMwasmnuz3NVq87oq9Wa4Ha8ESj7SqYzObfBVSCj63yVMpwUMalgmoXg3UBX2fLqqkBkLpEvY5YgAHzgAA8Elygx1ugBRdAgVBqSZ4Wb1-IAWRgBBEVpgQA&html=Q&css=Q

Expected output

AspectBase: attach to root
SelectionAspect: attach to root
ProjectSelection: attach to root

Actual output

Error: super.OverrideIssue.AspectBase`1.Attach1505 is not a function

Related information

  • Fable version: dotnet fable --version
    4.20.0
  • Operating system
    MacOS
@MangelMaxime
Copy link
Member

Like you pointed out, I suppose the line:

super["Examples.AspectBase`1.Attach1505"](owner);

should be generated to:

super["Examples.AspectBase`1.Attach2B595"](owner);

@davedawkins
Copy link
Contributor Author

I think so, yes

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