Skip to content

Commit aa3da27

Browse files
Use benevolent union when we cast values
1 parent 61a4dc1 commit aa3da27

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
@@ -847,18 +847,27 @@ public function walkSelectExpression($selectExpression)
847847
// the driver and PHP version.
848848
// Here we assume that the value may or may not be casted to
849849
// string by the driver.
850-
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type {
850+
$casted = false;
851+
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$casted): Type {
851852
if ($type instanceof UnionType || $type instanceof IntersectionType) {
852853
return $traverse($type);
853854
}
854855
if ($type instanceof IntegerType || $type instanceof FloatType) {
856+
$casted = true;
855857
return TypeCombinator::union($type->toString(), $type);
856858
}
857859
if ($type instanceof BooleanType) {
860+
$casted = true;
858861
return TypeCombinator::union($type->toInteger()->toString(), $type);
859862
}
860863
return $traverse($type);
861864
});
865+
866+
// Since we made supposition about possibly casted values,
867+
// we can only provide a benevolent union.
868+
if ($casted && $type instanceof UnionType) {
869+
$type = TypeUtils::toBenevolentUnion($type);
870+
}
862871
}
863872

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

0 commit comments

Comments
 (0)