Skip to content

Conversation

@VincentLanglet
Copy link
Collaborator

Close #136

@VincentLanglet
Copy link
Collaborator Author

Any idea why

new ReflectionClass(rand(0, 1) === 0 ? static::class : Throwable::class);

is now throwing an exception @pepakriz ?

@VincentLanglet
Copy link
Collaborator Author

Turns out that the tests are working with phpstan 0.12.54 but not anymore since phpstan 0.12.55

Maybe you can help me on this @ondrejmirtes ? Why the two following lines have a different behaviour

		new ReflectionClass(rand(0, 1) === 0 ? self::class : Throwable::class);
		new ReflectionClass(rand(0, 1) === 0 ? static::class : Throwable::class);

The code used is

	private function resolveReflectionClass(New_ $newNode, Scope $scope): Type
	{
		$reflectionExceptionType = new ObjectType(ReflectionException::class);
		if (!isset($newNode->args[0])) {
			return $reflectionExceptionType;
		}

		$valueType = $this->resolveType($newNode->args[0]->value, $scope);
		foreach (TypeUtils::getConstantStrings($valueType) as $constantString) {
			if (!$this->broker->hasClass($constantString->getValue())) {
				return $reflectionExceptionType;
			}

			$valueType = TypeCombinator::remove($valueType, $constantString);
		}

		if (!$valueType instanceof NeverType) {
			return $reflectionExceptionType;
		}

		return new VoidType();
	}

@VincentLanglet
Copy link
Collaborator Author

Seems like TypeUtils::getConstantStrings returns

array(2) {
  [0]=>
  object(PHPStan\Type\Constant\ConstantStringType)#24947 (2) {
    ["value":"PHPStan\Type\Constant\ConstantStringType":private]=>
    string(65) "Pepakriz\PHPStanExceptionRules\Rules\PhpInternalFunctions\Example"
    ["isClassString":"PHPStan\Type\Constant\ConstantStringType":private]=>
    bool(true)
  }
  [1]=>
  object(PHPStan\Type\Constant\ConstantStringType)#24958 (2) {
    ["value":"PHPStan\Type\Constant\ConstantStringType":private]=>
    string(9) "Throwable"
    ["isClassString":"PHPStan\Type\Constant\ConstantStringType":private]=>
    bool(true)
  }
}

for new ReflectionClass(rand(0, 1) === 0 ? self::class : Throwable::class); but an empty array for static::class.

@VincentLanglet
Copy link
Collaborator Author

Created phpstan/phpstan#4233

@VincentLanglet VincentLanglet merged commit 5c9012d into pepakriz:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native division does not throw ArithemticError

2 participants