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

[Python] Invalid code generated when calling a getter method from abstract getter member #3597

Closed
MangelMaxime opened this issue Nov 19, 2023 · 0 comments · Fixed by #3622
Closed
Labels
python Python

Comments

@MangelMaxime
Copy link
Member

Description

The following code when targeting Python generates an invalid code:

module Main

type IEncode =
    abstract toString : (int -> string -> string) with get

[<AbstractClass>]
type TestRunner<'Test, 'JsonValue> () =
    abstract Encode : IEncode with get

let toString (spaces : int) (value : string) =
    String.replicate 4 " " + value

type PythonEncode() =
    interface IEncode with
        override _.toString = toString

type PythonTestRunner() =
    inherit TestRunner<obj, obj>()

    override _.Encode = PythonEncode()

[<EntryPoint>]
let main args =
    let runner = PythonTestRunner()

    let x =
        runner.Encode.toString 4 "maxime"

    printfn "%A" x
    0

Python

#...

def main(args: Array[str]) -> int:
    runner: PythonTestRunner = PythonTestRunner__ctor()
    x: str = str(runner.Main_TestRunner_2_get_Encode())
    to_console(printf("%A"))(x)
    return 0

#...

The line

x: str = str(runner.Main_TestRunner_2_get_Encode())

should be

x: str = str(runner.Main_TestRunner_2_get_Encode().to_string(4, "maxime"))

Related information

  • Fable version: 4.5.0
  • Operating system: OSX
@MangelMaxime MangelMaxime added the python Python label Nov 19, 2023
@MangelMaxime MangelMaxime changed the title [Python] Invalid code generated when calling method from abstract getter member [Python] Invalid code generated when calling a getter method from abstract getter member Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant