Skip to content

Commit 2883214

Browse files
Use benevolent union when we cast values
1 parent 4893ef6 commit 2883214

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Type/Doctrine/Query/QueryResultTypeWalker.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,18 +849,27 @@ public function walkSelectExpression($selectExpression): string
849849
// the driver and PHP version.
850850
// Here we assume that the value may or may not be casted to
851851
// string by the driver.
852-
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type {
852+
$casted = false;
853+
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$casted): Type {
853854
if ($type instanceof UnionType || $type instanceof IntersectionType) {
854855
return $traverse($type);
855856
}
856857
if ($type instanceof IntegerType || $type instanceof FloatType) {
858+
$casted = true;
857859
return TypeCombinator::union($type->toString(), $type);
858860
}
859861
if ($type instanceof BooleanType) {
862+
$casted = true;
860863
return TypeCombinator::union($type->toInteger()->toString(), $type);
861864
}
862865
return $traverse($type);
863866
});
867+
868+
// Since we made supposition about possibly casted values,
869+
// we can only provide a benevolent union.
870+
if ($casted && $type instanceof UnionType) {
871+
$type = TypeUtils::toBenevolentUnion($type);
872+
}
864873
}
865874

866875
$this->addScalar($resultAlias, $type);

0 commit comments

Comments
 (0)