uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Herencia de mixins: se valida llamada a self erróneamente #2006

Open fdodino opened 3 years ago

fdodino commented 3 years ago
mixin Energy {
    var property energy = 100
    method reduceEnergy(amount) {
        energy = energy - amount
    }
}

mixin GetsHurt inherits Energy {
    method receiveDamage(amount) {
//        self.energy(self.energy() - amount)
        self.reduceEnergy(amount)
    }
    method energy()
    method energy(newEnergy)
}

// más definiciones
mixin Attacks {
    var property power = 10
    method attack(other) {
        other.receiveDamage(power)
        self.energy(self.energy() - 1)
    }

    method energy()
    method energy(newEnergy)
}

class Warrior {

}

me marca como erróneo self.reduceEnergy pero si ejecutamos este test:

import example.*

test "testX" {
    const warrior1 = object inherits GetsHurt and Attacks and Warrior {}
    console.println(warrior1.energy())
    assert.equals(100, warrior1.energy())

    const warrior2 = object inherits GetsHurt and Attacks and Warrior {}
    assert.equals(100, warrior2.energy())

    warrior1.attack(warrior2)

    assert.equals(90, warrior2.energy())
    assert.equals(99, warrior1.energy())
}

funciona perfectamente en runtime.

image