mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix implicitly nullable type detection in stubs
This commit is contained in:
@@ -394,6 +394,10 @@ class SimpleType {
|
||||
return $this->isBuiltin && $this->name === 'array';
|
||||
}
|
||||
|
||||
public function isMixed(): bool {
|
||||
return $this->isBuiltin && $this->name === 'mixed';
|
||||
}
|
||||
|
||||
public function toTypeCode(): string {
|
||||
assert($this->isBuiltin);
|
||||
switch ($this->name) {
|
||||
@@ -4233,7 +4237,7 @@ function parseFunctionLike(
|
||||
$type && !$type->isNullable()
|
||||
) {
|
||||
$simpleType = $type->tryToSimpleType();
|
||||
if ($simpleType === null) {
|
||||
if ($simpleType === null || !$simpleType->isMixed()) {
|
||||
throw new Exception("Parameter $varName has null default, but is not nullable");
|
||||
}
|
||||
}
|
||||
@@ -4342,13 +4346,26 @@ function parseConstLike(
|
||||
throw new Exception("Missing type for constant " . $name->__toString());
|
||||
}
|
||||
|
||||
$constType = $type ? Type::fromNode($type) : null;
|
||||
$constPhpDocType = $phpDocType ? Type::fromString($phpDocType) : null;
|
||||
|
||||
if ($const->value instanceof Expr\ConstFetch &&
|
||||
$const->value->name->toLowerString() === "null" &&
|
||||
$constType && !$constType->isNullable()
|
||||
) {
|
||||
$simpleType = $constType->tryToSimpleType();
|
||||
if ($simpleType === null || !$simpleType->isMixed()) {
|
||||
throw new Exception("Constant " . $name->__toString() . " has null value, but is not nullable");
|
||||
}
|
||||
}
|
||||
|
||||
return new ConstInfo(
|
||||
$name,
|
||||
$flags,
|
||||
$const->value,
|
||||
$prettyPrinter->prettyPrintExpr($const->value),
|
||||
$type ? Type::fromNode($type) : null,
|
||||
$phpDocType ? Type::fromString($phpDocType) : null,
|
||||
$constType,
|
||||
$constPhpDocType,
|
||||
$deprecated,
|
||||
$cond,
|
||||
$cValue,
|
||||
@@ -4401,9 +4418,8 @@ function parseProperty(
|
||||
$propertyType && !$propertyType->isNullable()
|
||||
) {
|
||||
$simpleType = $propertyType->tryToSimpleType();
|
||||
if ($simpleType === null) {
|
||||
throw new Exception(
|
||||
"Property $class::\$$property->name has null default, but is not nullable");
|
||||
if ($simpleType === null || !$simpleType->isMixed()) {
|
||||
throw new Exception("Property $class::\$$property->name has null default, but is not nullable");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user