fable-compiler / Fable.Python

Python bindings for Fable
https://fable.io/docs/
MIT License
135 stars 10 forks source link

String index access isn't changed to zero-based in the generated python code #112

Closed vf42 closed 6 months ago

vf42 commented 6 months ago

Consider a sample F# function:

let test1 (s: string) : bool =
    if s.Length < 3 then false else s[3] = 'A'

When compiled to Python with Fable, I get the following output:

def test1(s: str) -> bool:
    if len(s) < 3:
        return False

    else: 
        return s[3] == "A"

Which results in incorrect behavior since in python list and string indices are zero-based.

Expected behavior: index access on the last line to be updated as s[2]

$ dotnet fable --version
4.16.0
vf42 commented 6 months ago

Realized this belongs in https://github.com/fable-compiler/Fable/issues