@@ -108,7 +108,7 @@ class QueryResultTypeWalker extends SqlWalker
108108	private  $ hasGroupByClause ;
109109
110110	/** @var bool */ 
111- 	private  $ hasCondition  ;
111+ 	private  $ hasWhereClause  ;
112112
113113	/** 
114114	 * @param Query<mixed> $query 
@@ -138,7 +138,7 @@ public function __construct($query, $parserResult, array $queryComponents)
138138		$ this  ->nullableQueryComponents  = [];
139139		$ this  ->hasAggregateFunction  = false ;
140140		$ this  ->hasGroupByClause  = false ;
141- 		$ this  ->hasCondition  = false ;
141+ 		$ this  ->hasWhereClause  = false ;
142142
143143		// The object is instantiated by Doctrine\ORM\Query\Parser, so receiving 
144144		// dependencies through the constructor is not an option. Instead, we 
@@ -181,6 +181,7 @@ public function walkSelectStatement(AST\SelectStatement $AST)
181181		$ this  ->typeBuilder ->setSelectQuery ();
182182		$ this  ->hasAggregateFunction  = $ this  ->hasAggregateFunction ($ AST  );
183183		$ this  ->hasGroupByClause  = $ AST  ->groupByClause  !== null ;
184+ 		$ this  ->hasWhereClause  = $ AST  ->whereClause  !== null ;
184185
185186		$ this  ->walkFromClause ($ AST  ->fromClause );
186187
@@ -594,8 +595,6 @@ public function walkOrderByItem($orderByItem)
594595	 */ 
595596	public  function  walkHavingClause ($ havingClause )
596597	{
597- 		$ this  ->hasCondition  = true ;
598- 
599598		return  $ this  ->marshalType (new  MixedType ());
600599	}
601600
@@ -1011,8 +1010,6 @@ public function walkUpdateItem($updateItem)
10111010	 */ 
10121011	public  function  walkWhereClause ($ whereClause )
10131012	{
1014- 		$ this  ->hasCondition  = true ;
1015- 
10161013		return  $ this  ->marshalType (new  MixedType ());
10171014	}
10181015
@@ -1300,10 +1297,10 @@ public function walkResultVariable($resultVariable)
13001297	 */ 
13011298	private  function  addScalar ($ alias , Type   $ type ): void 
13021299	{
1303- 		// Since we don't check the condition inside the WHERE or HAVING  
1300+ 		// Since we don't check the condition inside the WHERE 
13041301		// conditions, we cannot be sure all the union types are correct. 
13051302		// For exemple, a condition `WHERE foo.bar IS NOT NULL` could be added. 
1306- 		if  ($ this  ->hasCondition  && $ type  instanceof  UnionType) {
1303+ 		if  ($ this  ->hasWhereClause  && $ type  instanceof  UnionType) {
13071304			$ type  = TypeUtils::toBenevolentUnion ($ type );
13081305		}
13091306
0 commit comments