Skip to content

Commit

Permalink
Fix #1751 - Global variable types
Browse files Browse the repository at this point in the history
  • Loading branch information
PalumboN committed Mar 13, 2021
1 parent 513946c commit 81a99e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* XPECT_SETUP org.uqbar.project.wollok.tests.typesystem.xpect.TypeSystemXpectTestCase END_SETUP */

object o {
// XPECT type at xs --> List<Number>
const property xs = numbers
}

// XPECT type at numbers --> List<Number>
const numbers = [1,2,3]
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class ConstraintGenerator {
typeSystem.allTypes.add(classType)
}

def dispatch void addGlobals(WVariableDeclaration it) {
if (global) {
variable.newTypeVariable.beNonVoid
newTypeVariable.beVoid
}
}

// ************************************************************************
// ** Second pass / whole constraint generation
// ************************************************************************
Expand Down Expand Up @@ -121,7 +128,7 @@ class ConstraintGenerator {
// TODO Process supertype information: mixins
parentParameters?.arguments?.forEach[generateVariables]
members.forEach[generateVariables]
if (parentParameters !== null) objectParentConstraintsGenerator.add(it)
if(parentParameters !== null) objectParentConstraintsGenerator.add(it)
}

def dispatch void generate(WClass it) {
Expand All @@ -135,9 +142,9 @@ class ConstraintGenerator {
members.forEach[generateVariables]
typeSystem.allTypes.add(objectLiteralType)
newTypeVariable.beSealed(objectLiteralType)
if (parentParameters !== null) objectParentConstraintsGenerator.add(it)
if(parentParameters !== null) objectParentConstraintsGenerator.add(it)
}

def dispatch void generate(WSuite it) {
members.forEach[generateVariables]
tests.forEach[generateVariables]
Expand Down Expand Up @@ -192,7 +199,7 @@ class ConstraintGenerator {
def dispatch void generate(WParameter it) {
newTypeVariable.beNonVoid
}

def dispatch void generate(WTest it) {
elements.forEach[generateVariables]
}
Expand Down Expand Up @@ -246,19 +253,21 @@ class ConstraintGenerator {
initialValue.generateVariables
initializerConstraintsGenerator.add(it)
}

// ************************************************************************
// ** Variables
// ************************************************************************
def dispatch void generate(WVariableDeclaration it) {
variable.newTypeVariable.beNonVoid
if (!global) {
variable.newTypeVariable.beNonVoid
newTypeVariable.beVoid
}

if (right !== null) {
right.generateVariables
variable.beSupertypeOf(right)
}

newTypeVariable.beVoid
}

def dispatch void generate(WAssignment it) {
Expand Down Expand Up @@ -378,7 +387,7 @@ class ConstraintGenerator {
memberCallArguments.forEach[generateVariables]
superInvocationConstraintsGenerator.add(it)
}

// ************************************************************************
// ** Method overriding
// ************************************************************************
Expand All @@ -404,7 +413,7 @@ class ConstraintGenerator {
def dispatch WollokType asWollokType(WClass wClass) {
classType(wClass)
}

def dispatch WollokType asWollokType(WSuite suite) {
suiteType(suite)
}
Expand Down

0 comments on commit 81a99e2

Please sign in to comment.