uqbar-project / wollok

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

Inconsistent type inference #1500

Open matifreyre opened 6 years ago

matifreyre commented 6 years ago

Working on version 1.7.1, the type-system seems to be erring somehow for the following piece of code. I'm not sure of what the rule should be, but it's following different rules for almost equal objects:

object bienvenidor {
    var property estrategia

    method saludar(){
        estrategia.saludar(self)
    }

    method decirHola(){
        console.println("Hola")
    }
}

object despedidor {
    var property estrategia

    method saludar(){
        estrategia.saludar(self)
    }

    method decirChau(){
        console.println("Chau")
    }
}

object despedir {
    method saludar(alguien) {
        alguien.decirChau()
    }
}

object bienvenir {
    method saludar(alguien) {
        alguien.decirHola()
    }
}

The types for both estrategia variables should be inferred equally (not the same type, but applying the same rules), either both should identify both objects that implement saludar (bienvenir and despedir) or both should identify the specific object that implements saludar with code that can be evaluated using self as a parameter without syntax errors. Instead, the inferred types are the following:

image

It can be seen that the types for bienvenir and despedir parameters on saludar are correct. I guess that's what is used when inferring on bienvenidor, but not on despedidor.

PalumboN commented 5 years ago

Puede que este haya sido un problema de cache? Yo lo acabo de probar en la versión 1.7.2 y me dice que la estrategia de despedidor es solamente de tipo despedir (como se espera).

matifreyre commented 5 years ago

En 1.7.7 todavía pasa. Si se invierten las definiciones de los saludadores o de las estrategias, funciona bien y determina un solo tipo de estrategia para cada saludador. Si se ponen en este orden: despedir, bienvenidor, despedidor, bienvenir, entonces ambos saludadores tienen el mismo problema.

PalumboN commented 4 years ago

Creo que esto se soluciona con https://github.com/uqbar-project/wollok/issues/1890