-
Notifications
You must be signed in to change notification settings - Fork 39
'this' as default parameter value in a function refers to the wrong object #991
Open
Labels
Description
Here's a short example:
A: class { value := 0 other: Int init: func foo: func (v := this value) { this other = v } } B: class { whatever := 1 init: func bar: func (w := this whatever) -> Int { a := A new() a foo() a other } } b := B new() something := b bar(2)
The value of v in foo should be this value but this does not point to itself but rather to the calling object b and fails with: error: ‘example__B’ has no member named 'value'
The same happens if the last line is replaced with something := b bar(), then the default value of w in bar fails because this is undeclared (we're not calling from any object).
(I assume this is not by design.)