Skip to content

Commit

Permalink
Fixes #625: Values passed through WITH have the wrong type
Browse files Browse the repository at this point in the history
  • Loading branch information
systay committed Jun 28, 2012
1 parent b7fc3e5 commit e443b70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cypher/CHANGES.txt
@@ -1,3 +1,8 @@
1.8
--------------------
o Fixes problem when graph elements are deleted multiple times in the same query
o Fixes #625: Values passed through WITH have the wrong type

1.8.M05 (2012-06-21)
--------------------
o CREATE and RELATE can now introduce path identifiers
Expand Down
Expand Up @@ -30,12 +30,12 @@ abstract class Expression extends (Map[String, Any] => Any) {
def apply(m: Map[String, Any]) = m.getOrElse(identifier.name, compute(m))

val identifier: Identifier
def declareDependencies(extectedType: AnyType): Seq[Identifier]
def dependencies(extectedType: AnyType): Seq[Identifier] = {
def declareDependencies(expectedType: AnyType): Seq[Identifier]
def dependencies(expectedType: AnyType): Seq[Identifier] = {
val myType = identifier.typ
if (!extectedType.isAssignableFrom(myType))
throw new SyntaxException(identifier.name + " expected to be of type " + extectedType + " but it is of type " + identifier.typ)
declareDependencies(extectedType)
if (!expectedType.isAssignableFrom(myType))
throw new SyntaxException(identifier.name + " expected to be of type " + expectedType + " but it is of type " + identifier.typ)
declareDependencies(expectedType)
}

def rewrite(f: Expression => Expression): Expression
Expand Down
Expand Up @@ -45,10 +45,11 @@ class SymbolTable(val identifiers: Identifier*) {

def assertHas(expected: Identifier) {
identifiers.find(_.name == expected.name) match {
case None => throwMissingKey(expected.name)
case Some(existing) => if (!expected.typ.isAssignableFrom(existing.typ)) {
throw new CypherTypeException("Expected `" + expected.name + "` to be a " + expected.typ + " but it was " + existing.typ)
}
case None => throwMissingKey(expected.name)
case Some(existing) =>
if (!(expected.typ.isAssignableFrom(existing.typ) || existing.typ.isAssignableFrom(expected.typ))) {
throw new CypherTypeException("Expected `" + expected.name + "` to be a " + expected.typ + " but it was " + existing.typ)
}
}
}

Expand Down
Expand Up @@ -2112,6 +2112,13 @@ RETURN x0.name?
assert(result().toList.size === 4)
}

@Test
def with_should_not_forget_original_type() {
val result = parseAndExecute("create a={x:8} with a.x as foo return sum(foo)")

assert(result.toList === List(Map("sum(foo)" -> 8)))
}

@Ignore("This pattern is currently not supported. Revisit when we do support it.")
@Test
def two_double_optional_paths_with_shared_relationships() {
Expand Down

0 comments on commit e443b70

Please sign in to comment.