diff --git a/build/gen_stub.php b/build/gen_stub.php index dc762f8d6cb..3bf9fb995dc 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -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"); } }