Skip to content

Commit 7ca3bc1

Browse files
Use benevolent union when we cast values
1 parent b4c3152 commit 7ca3bc1

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

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

0 commit comments

Comments
 (0)