Skip to content

Navigation Menu

Sign in
Sign up

Weird behaviour with setters calling associated getter #1002

Open

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      AltStyle によって変換されたページ (->オリジナル) /