ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
401 stars 40 forks source link

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

Open marcusnaslund opened 8 years ago

marcusnaslund commented 8 years ago

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 commented 8 years ago

(I assume this is not by design.)

haha, definitely not by design

alexnask commented 8 years ago

Huh, fun one.