Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcusnaslund opened this issue Apr 7, 2016 · 2 comments

Comments

@marcusnaslund
Copy link
Contributor

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

@fasterthanlime
Copy link
Collaborator

(I assume this is not by design.)

haha, definitely not by design

@alexnask
Copy link
Collaborator

alexnask commented Apr 8, 2016

Huh, fun one.

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

No branches or pull requests

3 participants