Skip to content

Commit

Permalink
UnionType - carry information that it's normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 9, 2022
1 parent 1a59fe1 commit 96e4443
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public static function union(Type ...$types): Type
}
}

return new UnionType($types);
return new UnionType($types, true);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UnionType implements CompoundType
* @api
* @param Type[] $types
*/
public function __construct(private array $types)
public function __construct(private array $types, private bool $normalized = false)
{
$throwException = static function () use ($types): void {
throw new ShouldNotHappenException(sprintf(
Expand Down Expand Up @@ -74,6 +74,11 @@ public function getTypes(): array
return $this->types;
}

public function isNormalized(): bool
{
return $this->normalized;
}

/**
* @return Type[]
*/
Expand Down Expand Up @@ -836,7 +841,7 @@ public function tryRemove(Type $typeToRemove): ?Type
*/
public static function __set_state(array $properties): Type
{
return new self($properties['types']);
return new self($properties['types'], $properties['normalized']);
}

/**
Expand Down

1 comment on commit 96e4443

@staabm
Copy link
Contributor

@staabm staabm commented on 96e4443 Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn‘t this change require a new Cache-Version key?

https://github.com/phpstan/phpstan-src/blob/1.9.x/src/Analyser/ResultCache/ResultCacheManager.php#L47

this came up in the phpstan-dba@phpstan-dev builds

-- --------------------------------------------------------------------------- 
     Error                                                                      
 -- --------------------------------------------------------------------------- 
     Internal error: Internal error: PHPStan\Type\UnionType::__construct():     
     Argument #2 ($normalized) must be of type bool, null given, called in      
     phar:///home/runner/work/phpstan-dba/phpstan-dba/vendor/phpstan/phpstan/p  
     hpstan.phar/src/Type/UnionType.php on line 820 in file                     
     /home/runner/work/phpstan-dba/phpstan-dba/src/QueryReflection/PdoPgSqlQue  
     ryReflector.php                                                            
     Run PHPStan with -v option and post the stack trace to:                    
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md       
     Internal error: Internal error: PHPStan\Type\UnionType::__construct():     
     Argument #2 ($normalized) must be of type bool, null given, called in      
     phar:///home/runner/work/phpstan-dba/phpstan-dba/vendor/phpstan/phpstan/p  
     hpstan.phar/src/Type/UnionType.php on line 820 in file                     
     /home/runner/work/phpstan-dba/phpstan-dba/src/QueryReflection/PdoMysqlQue  
     ryReflector.php                                                            
     Run PHPStan with -v option and post the stack trace to:                    
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md       
     Internal error: Internal error: PHPStan\Type\UnionType::__construct():     
     Argument #2 ($normalized) must be of type bool, null given, called in      
     phar:///home/runner/work/phpstan-dba/phpstan-dba/vendor/phpstan/phpstan/p  
     hpstan.phar/src/Type/UnionType.php on line 820 in file                     
     /home/runner/work/phpstan-dba/phpstan-dba/src/DbSchema/SchemaHasherMysql.  
     php                                                                        
     Run PHPStan with -v option and post the stack trace to:                    
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md       
     Child process error (exit code 1):                                         
 -- --------------------------------------------------------------------------- 

Please sign in to comment.