Skip to content

Commit

Permalink
Merge pull request neo4j#3662 from davidegrohmann/2.0-number-not-coer…
Browse files Browse the repository at this point in the history
…cible-to-boolean

Integer and Float are not coercible to Boolean
  • Loading branch information
davidegrohmann committed Dec 15, 2014
2 parents 6e755ef + 78ca30e commit e091f42
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.neo4j.cypher.internal.compiler.v2_0.symbols
object FloatType {
val instance = new FloatType() {
val parentType = CTNumber
override lazy val coercibleTo: Set[CypherType] = Set(CTBoolean)
override val toString = "Float"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package org.neo4j.cypher.internal.compiler.v2_0.symbols
object IntegerType {
val instance = new IntegerType() {
val parentType = CTNumber
override lazy val coercibleTo: Set[CypherType] = Set(CTBoolean, CTFloat)
override lazy val coercibleTo: Set[CypherType] = Set(CTFloat)
override val toString = "Integer"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class AndTest extends InfixExpressionTestBase(And(_, _)(DummyPosition(0))) {

@Test
def shouldCoerceArguments() {
testValidTypes(CTInteger, CTBoolean)(CTBoolean)
testValidTypes(CTBoolean, CTInteger)(CTBoolean)
testInvalidApplication(CTInteger, CTBoolean)("Type mismatch: expected Boolean but was Integer")
testInvalidApplication(CTBoolean, CTInteger)("Type mismatch: expected Boolean but was Integer")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class OrTest extends InfixExpressionTestBase(Or(_, _)(DummyPosition(0))) {

@Test
def shouldCoerceArguments() {
testValidTypes(CTInteger, CTBoolean)(CTBoolean)
testValidTypes(CTBoolean, CTInteger)(CTBoolean)
testInvalidApplication(CTInteger, CTBoolean)("Type mismatch: expected Boolean but was Integer")
testInvalidApplication(CTBoolean, CTInteger)("Type mismatch: expected Boolean but was Integer")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class XorTest extends InfixExpressionTestBase(Xor(_, _)(DummyPosition(0))) {

@Test
def shouldCoerceArguments() {
testValidTypes(CTInteger, CTBoolean)(CTBoolean)
testValidTypes(CTBoolean, CTInteger)(CTBoolean)
testInvalidApplication(CTInteger, CTBoolean)("Type mismatch: expected Boolean but was Integer")
testInvalidApplication(CTBoolean, CTInteger)("Type mismatch: expected Boolean but was Integer")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ class TypeSpecTest extends CypherFunSuite {
}

test("should identify coercions") {
assertEquals(CTBoolean.invariant, CTFloat.covariant.coercions)
assertEquals(CTBoolean | CTFloat, CTInteger.covariant.coercions)
assertEquals(CTBoolean | CTFloat, (CTFloat | CTInteger).coercions)
assertEquals(CTFloat.invariant, CTInteger.covariant.coercions)
assertEquals(CTFloat.invariant, (CTFloat | CTInteger).coercions)
assertEquals(CTBoolean.invariant, CTCollection(CTAny).covariant.coercions)
assertEquals(CTBoolean.invariant, TypeSpec.exact(CTCollection(CTPath)).coercions)
assertEquals(CTBoolean | CTFloat, TypeSpec.all.coercions)
Expand All @@ -304,7 +303,7 @@ class TypeSpecTest extends CypherFunSuite {
assertEquals(CTFloat.invariant, CTInteger intersectOrCoerce CTFloat)
assertEquals(TypeSpec.none, CTNumber intersectOrCoerce CTFloat)
assertEquals(CTBoolean.invariant, CTCollection(CTAny).covariant intersectOrCoerce CTBoolean)
assertEquals(CTBoolean.invariant, CTNumber.covariant intersectOrCoerce CTBoolean)
assertEquals(TypeSpec.none, CTNumber.covariant intersectOrCoerce CTBoolean)
assertEquals(CTBoolean.invariant, CTCollection(CTAny).covariant intersectOrCoerce CTBoolean)
assertEquals(TypeSpec.none, CTInteger intersectOrCoerce CTString)
}
Expand All @@ -314,7 +313,7 @@ class TypeSpecTest extends CypherFunSuite {
assertEquals(CTFloat.invariant, CTInteger constrainOrCoerce CTFloat)
assertEquals(TypeSpec.none, CTNumber constrainOrCoerce CTFloat)
assertEquals(CTBoolean.invariant, CTCollection(CTAny).covariant constrainOrCoerce CTBoolean)
assertEquals(CTBoolean.invariant, CTNumber.covariant constrainOrCoerce CTBoolean)
assertEquals(TypeSpec.none, CTNumber.covariant constrainOrCoerce CTBoolean)
assertEquals(CTBoolean.invariant, CTCollection(CTAny).covariant constrainOrCoerce CTBoolean)
assertEquals(TypeSpec.none, CTInteger constrainOrCoerce CTString)
}
Expand Down

0 comments on commit e091f42

Please sign in to comment.