@@ -107,7 +107,7 @@ class QueryResultTypeWalker extends SqlWalker
107107 private $ hasGroupByClause ;
108108
109109 /** @var bool */
110- private $ hasCondition ;
110+ private $ hasWhereClause ;
111111
112112 /**
113113 * @param Query<mixed> $query
@@ -137,7 +137,7 @@ public function __construct($query, $parserResult, array $queryComponents)
137137 $ this ->nullableQueryComponents = [];
138138 $ this ->hasAggregateFunction = false ;
139139 $ this ->hasGroupByClause = false ;
140- $ this ->hasCondition = false ;
140+ $ this ->hasWhereClause = false ;
141141
142142 // The object is instantiated by Doctrine\ORM\Query\Parser, so receiving
143143 // dependencies through the constructor is not an option. Instead, we
@@ -180,6 +180,7 @@ public function walkSelectStatement(AST\SelectStatement $AST)
180180 $ this ->typeBuilder ->setSelectQuery ();
181181 $ this ->hasAggregateFunction = $ this ->hasAggregateFunction ($ AST );
182182 $ this ->hasGroupByClause = $ AST ->groupByClause !== null ;
183+ $ this ->hasWhereClause = $ AST ->whereClause !== null ;
183184
184185 $ this ->walkFromClause ($ AST ->fromClause );
185186
@@ -593,8 +594,6 @@ public function walkOrderByItem($orderByItem)
593594 */
594595 public function walkHavingClause ($ havingClause )
595596 {
596- $ this ->hasCondition = true ;
597-
598597 return $ this ->marshalType (new MixedType ());
599598 }
600599
@@ -1010,8 +1009,6 @@ public function walkUpdateItem($updateItem)
10101009 */
10111010 public function walkWhereClause ($ whereClause )
10121011 {
1013- $ this ->hasCondition = true ;
1014-
10151012 return $ this ->marshalType (new MixedType ());
10161013 }
10171014
@@ -1299,10 +1296,10 @@ public function walkResultVariable($resultVariable)
12991296 */
13001297 private function addScalar ($ alias , Type $ type ): void
13011298 {
1302- // Since we don't check the condition inside the WHERE or HAVING
1299+ // Since we don't check the condition inside the WHERE
13031300 // conditions, we cannot be sure all the union types are correct.
13041301 // For exemple, a condition `WHERE foo.bar IS NOT NULL` could be added.
1305- if ($ this ->hasCondition && $ type instanceof UnionType) {
1302+ if ($ this ->hasWhereClause && $ type instanceof UnionType) {
13061303 $ type = TypeUtils::toBenevolentUnion ($ type );
13071304 }
13081305
0 commit comments