Skip to content

Commit

Permalink
Merge 30bb2b1 into ffa270c
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Dec 13, 2018
2 parents ffa270c + 30bb2b1 commit 4245771
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ program p {
// XPECT type at algo --> Any
var algo

// XPECT type at obj --> { }
var obj = object { }

// XPECT type at nullable --> Any
var nullable = null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* XPECT_SETUP org.uqbar.project.wollok.tests.typesystem.xpect.TypeSystemXpectTestCase END_SETUP */

class Persona {

// XPECT type at hambriento --> { cena }
var hambriento = object {
var a = 0

method cena() {
return a
}
}

// XPECT type at charlatan --> { habla }
var charlatan = object {
method habla() = "Hola"
}

// XPECT type at multifacetico --> { habla; cena }
var multifacetico = object {
method habla() = "Chau"
method cena() = 100
}

// XPECT type at friki --> { habla; cena }
var friki = object {
method habla() = 42
method cena() = "Wollok"
}

// XPECT methodType at comida() --> () => Number
method comida() = hambriento.cena()

// XPECT methodType at comidaMulti() --> () => Number
method comidaMulti() = multifacetico.cena()

// XPECT methodType at comidaRara() --> () => String
method comidaRara() = friki.cena()

// XPECT warnings --> "{ habla } does not understand cena()" at "charlatan.cena()"
method comidaConLaBocaAbierta() = charlatan.cena()


// XPECT methodType at charla() --> () => String
method charla() = charlatan.habla()

// XPECT methodType at charlaMulti() --> () => String
method charlaMulti() = multifacetico.habla()

// XPECT methodType at charlaRara() --> () => Number
method charlaRara() = friki.habla()

// XPECT warnings --> "{ cena } does not understand habla()" at "hambriento.habla()"
method charlaConEstomagoVacio() = hambriento.habla()


// XPECT methodType at hacerHablarACharlatan() --> () => String
method hacerHablarACharlatan() = self.hacerHablar(charlatan)

// XPECT methodType at hacerHablarAMultifacetico() --> () => String
method hacerHablarAMultifacetico() = self.hacerHablar(multifacetico)

// XPECT! methodType at hacerHablarAFriki() --> () => Number
// method hacerHablarAFriki() = self.hacerHablar(friki)

// XPECT! warnings --> "{ cena } doesn't match with { habla } ... TO CHECK"
// method hacerHablarAHambriento() = self.hacerHablar(hambriento)

// XPECT methodType at hacerHablar(personalidad) --> (({ habla ; cena }|{ habla })) => String
method hacerHablar(personalidad) = personalidad.habla()


// XPECT methodType at hacerHablarQueNuncaSeUsa(personalidad) --> (Any) => Any
method hacerHablarQueNuncaSeUsa(personalidad) = personalidad.habla()

// XPECT methodType at charlatanString() --> () => String
method charlatanString() = charlatan.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class BasicType implements WollokType {

override instanceFor(TypeVariable parent) { this }

override toString() { name }
override toString() { getName }

override beSubtypeOf(WollokType type) {
// By default we have nothing to do, this is only for generic type instances to implement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import org.uqbar.project.wollok.wollokDsl.WMethodDeclaration
import org.uqbar.project.wollok.wollokDsl.WObjectLiteral
import org.uqbar.project.wollok.wollokDsl.WParameter

import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.*
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.allUntypedMethods
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.lookupMethod
import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.methods

/**
*
Expand Down Expand Up @@ -71,7 +73,7 @@ class ObjectLiteralType extends BasicType implements ConcreteType {
typeSystem.type(method)
}

override getAllMessages() { object.methods.map[messageType] }
override getAllMessages() { object.allUntypedMethods.map[messageType] }

override dispatch refine(WollokType previous) {
val intersectMessages = allMessages.filter[previous.understandsMessage(it)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.uqbar.project.wollok.typesystem;

import org.eclipse.emf.ecore.EObject;
import org.uqbar.project.wollok.wollokDsl.WObjectLiteral;

/**
* I can search for types in a program, parsing them out of a string.
Expand All @@ -13,5 +14,5 @@ public interface TypeProvider {
public GenericType genericType(EObject context, String classFQN, String... typeParameterNames);
public GenericType closureType(EObject context, int parameterCount);
public NamedObjectType objectType(EObject context, String classFQN);

public ObjectLiteralType objectLiteralType(WObjectLiteral context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UnionType extends BasicType {
new(ConcreteType... types) {
// I will order them by name to have the same expected order,
// so it does not matter the order of the types in the textual representation.
super(types.sortBy[name].join('(', '|', ')', [toString]))
super(types.sortBy[name].join('(', '|', ')', [name]))
this.types = types.toList
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import static org.uqbar.project.wollok.scoping.WollokResourceCache.*

import static extension org.uqbar.project.wollok.model.WollokModelExtensions.fqn
import static extension org.uqbar.project.wollok.typesystem.annotations.TypeDeclarations.*
import org.uqbar.project.wollok.wollokDsl.WObjectLiteral
import org.uqbar.project.wollok.typesystem.ObjectLiteralType

/**
* @author npasserini
Expand Down Expand Up @@ -264,6 +266,10 @@ class ConstraintBasedTypeSystem implements TypeSystem, TypeProvider {
new ClosureType(finder.getClosureClass(context), this, typeParameterNames)
}

override objectLiteralType(WObjectLiteral context) {
new ObjectLiteralType(context, this)
}

/**
* Not all classes are actual types, as some have type parameters and therefore are generic types (aka type factories).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.uqbar.project.wollok.wollokDsl.WMethodDeclaration
import org.uqbar.project.wollok.wollokDsl.WNamedObject
import org.uqbar.project.wollok.wollokDsl.WNullLiteral
import org.uqbar.project.wollok.wollokDsl.WNumberLiteral
import org.uqbar.project.wollok.wollokDsl.WObjectLiteral
import org.uqbar.project.wollok.wollokDsl.WParameter
import org.uqbar.project.wollok.wollokDsl.WPostfixOperation
import org.uqbar.project.wollok.wollokDsl.WProgram
Expand Down Expand Up @@ -124,6 +125,12 @@ class ConstraintGenerator {
constructors.forEach[generateVariables]
}

def dispatch void generate(WObjectLiteral it) {
// TODO Process supertype information: parent and mixins
members.forEach[generateVariables]
newTypeVariable.beSealed(objectLiteralType(it))
}

// ************************************************************************
// ** Methods and closures
// ************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class SubtypingRules {
false
}

/** TODO Structural types */
static def dispatch isSuperTypeOf(StructuralType supertype, WollokType subtype) {
throw new UnsupportedOperationException("Structural types are not supported yet. ")
}

static def dispatch isSuperTypeOf(ClassInstanceType supertype, ClassInstanceType subtype) {
supertype.clazz.isSuperTypeOf(subtype.clazz)
}
Expand All @@ -55,4 +50,9 @@ class SubtypingRules {
static def dispatch isSuperTypeOf(WollokType supertype, StructuralType subtype) {
throw new UnsupportedOperationException(Messages.RuntimeTypeSystemException_STRUCTURAL_TYPES_NOT_SUPPORTED)
}

/** TODO Structural types */
static def dispatch isSuperTypeOf(StructuralType supertype, WollokType subtype) {
throw new UnsupportedOperationException(Messages.RuntimeTypeSystemException_STRUCTURAL_TYPES_NOT_SUPPORTED)
}
}

0 comments on commit 4245771

Please sign in to comment.