Skip to content

Weird behaviour with setters calling associated getter #1002

Description

@marcusnaslund

Example 1 (associated getter):

Test: class {
    value: Int {
        get { return 2 }
        set (x) { 
            if (this value == 2)
                "two" println()
            else
                "not two, but: %i" printfln(this value)
         }
    }
    init: func
}

x := Test new()
x value = 10

should print "two" but prints "not two, but: 0".

Example 2 (setter calling itself):

Same here. But:

Test: class {
    value: Int {
        get { return 2 }
        set (x) {
            "old value=%i" printfln(this value)
            this value = x
        }
    }
    init: func
}

x := Test new()
x value = 2
x value = 3
x value = 4

should always print "old value=2" but prints

old value=0
old value=2
old value=3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions