Skip to content

python target is confused with class taking a length: int argument #3496

@smoothdeveloper

Description

@smoothdeveloper
type Class(length: int) =
    member x.Length = length

let c = Class(10)
printfn $"{c.Length}"

AFAIU, it confuses access to length value and turns it into len(c).

def _expr126() -> TypeInfo:
    return class_type("Program.Class", None, Class)

class Class:
    def __init__(self, length: int) -> None:
        self.length: int = length or 0

Class_reflection = _expr126

def Class__ctor_Z524259A4(length: int) -> Class:
    return Class(length)

def Class__get_Length(x: Class) -> int:
    return len(x) # this does not look right

to_console(("" + str(Class__get_Length(Class__ctor_Z524259A4(10)))) + "")

workaround is to bind length:

type Class(length: int) =
    let length = length
    member x.Length = length

related: matthewcrews/SliceMap#4

cc: @dbrattli

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions