@@ -394,6 +394,10 @@ public function isArray(): bool {
394
394
return $ this ->isBuiltin && $ this ->name === 'array ' ;
395
395
}
396
396
397
+ public function isMixed (): bool {
398
+ return $ this ->isBuiltin && $ this ->name === 'mixed ' ;
399
+ }
400
+
397
401
public function toTypeCode (): string {
398
402
assert ($ this ->isBuiltin );
399
403
switch ($ this ->name ) {
@@ -4233,7 +4237,7 @@ function parseFunctionLike(
4233
4237
$type && !$type->isNullable()
4234
4238
) {
4235
4239
$simpleType = $type->tryToSimpleType();
4236
- if ($simpleType === null) {
4240
+ if ($simpleType === null || !$simpleType->isMixed() ) {
4237
4241
throw new Exception("Parameter $varName has null default, but is not nullable");
4238
4242
}
4239
4243
}
@@ -4342,13 +4346,26 @@ function parseConstLike(
4342
4346
throw new Exception("Missing type for constant " . $name->__toString());
4343
4347
}
4344
4348
4349
+ $constType = $type ? Type::fromNode($type) : null;
4350
+ $constPhpDocType = $phpDocType ? Type::fromString($phpDocType) : null;
4351
+
4352
+ if ($const->value instanceof Expr\ConstFetch &&
4353
+ $const->value->name->toLowerString() === "null" &&
4354
+ $constType && !$constType->isNullable()
4355
+ ) {
4356
+ $simpleType = $constType->tryToSimpleType();
4357
+ if ($simpleType === null || !$simpleType->isMixed()) {
4358
+ throw new Exception("Constant " . $name->__toString() . " has null value, but is not nullable");
4359
+ }
4360
+ }
4361
+
4345
4362
return new ConstInfo(
4346
4363
$name,
4347
4364
$flags,
4348
4365
$const->value,
4349
4366
$prettyPrinter->prettyPrintExpr($const->value),
4350
- $type ? Type::fromNode($type) : null ,
4351
- $phpDocType ? Type::fromString($phpDocType) : null ,
4367
+ $constType ,
4368
+ $constPhpDocType ,
4352
4369
$deprecated,
4353
4370
$cond,
4354
4371
$cValue,
@@ -4401,9 +4418,8 @@ function parseProperty(
4401
4418
$propertyType && !$propertyType->isNullable()
4402
4419
) {
4403
4420
$simpleType = $propertyType->tryToSimpleType();
4404
- if ($simpleType === null) {
4405
- throw new Exception(
4406
- "Property $class::\$$property->name has null default, but is not nullable");
4421
+ if ($simpleType === null || !$simpleType->isMixed()) {
4422
+ throw new Exception("Property $class::\$$property->name has null default, but is not nullable");
4407
4423
}
4408
4424
}
4409
4425
0 commit comments