Skip to content

Navigation Menu

Sign in
Sign up

'this' as default parameter value in a function refers to the wrong object #991

Open

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.)

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 によって変換されたページ (->オリジナル) /