@@ -109,7 +109,7 @@ class QueryResultTypeWalker extends SqlWalker
109109 private $ hasGroupByClause ;
110110
111111 /** @var bool */
112- private $ hasCondition ;
112+ private $ hasWhereClause ;
113113
114114 /**
115115 * @param Query<mixed> $query
@@ -139,7 +139,7 @@ public function __construct($query, $parserResult, array $queryComponents)
139139 $ this ->nullableQueryComponents = [];
140140 $ this ->hasAggregateFunction = false ;
141141 $ this ->hasGroupByClause = false ;
142- $ this ->hasCondition = false ;
142+ $ this ->hasWhereClause = false ;
143143
144144 // The object is instantiated by Doctrine\ORM\Query\Parser, so receiving
145145 // dependencies through the constructor is not an option. Instead, we
@@ -179,6 +179,7 @@ public function walkSelectStatement(AST\SelectStatement $AST): string
179179 $ this ->typeBuilder ->setSelectQuery ();
180180 $ this ->hasAggregateFunction = $ this ->hasAggregateFunction ($ AST );
181181 $ this ->hasGroupByClause = $ AST ->groupByClause !== null ;
182+ $ this ->hasWhereClause = $ AST ->whereClause !== null ;
182183
183184 $ this ->walkFromClause ($ AST ->fromClause );
184185
@@ -596,8 +597,6 @@ public function walkOrderByItem($orderByItem): string
596597 */
597598 public function walkHavingClause ($ havingClause ): string
598599 {
599- $ this ->hasCondition = true ;
600-
601600 return $ this ->marshalType (new MixedType ());
602601 }
603602
@@ -1033,8 +1032,6 @@ public function walkWhereClause($whereClause): string
10331032 */
10341033 public function walkConditionalExpression ($ condExpr ): string
10351034 {
1036- $ this ->hasCondition = true ;
1037-
10381035 return $ this ->marshalType (new MixedType ());
10391036 }
10401037
@@ -1322,10 +1319,10 @@ public function walkResultVariable($resultVariable): string
13221319 */
13231320 private function addScalar ($ alias , Type $ type ): void
13241321 {
1325- // Since we don't check the condition inside the WHERE or HAVING
1322+ // Since we don't check the condition inside the WHERE
13261323 // conditions, we cannot be sure all the union types are correct.
13271324 // For exemple, a condition `WHERE foo.bar IS NOT NULL` could be added.
1328- if ($ this ->hasCondition && $ type instanceof UnionType) {
1325+ if ($ this ->hasWhereClause && $ type instanceof UnionType) {
13291326 $ type = TypeUtils::toBenevolentUnion ($ type );
13301327 }
13311328
0 commit comments