Skip to content

Conversation

SplotyCode
Copy link
Contributor

Fixed phpstan/phpstan#13048. Essentially, T of (A|null) subtracted by A is T of mixed

@SplotyCode SplotyCode force-pushed the fix/nullable-templates branch 5 times, most recently from 19e6bbe to e20136d Compare August 28, 2025 21:50
This fixes issues like #13048. Currently, T of (A|null) subtracted by A is T of mixed
@SplotyCode SplotyCode force-pushed the fix/nullable-templates branch from e20136d to ed9d037 Compare August 28, 2025 22:07
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

  1. This fixes a bunch of other issues, please check https://github.com/phpstan/phpstan-src/actions/runs/17309059596 and add regression tests for them too.
  2. This has to be modified
    if (
    $boundTypeClass !== MixedType::class
    && $boundTypeClass !== ConstantArrayType::class
    && $boundTypeClass !== ArrayType::class
    && $boundTypeClass !== ConstantStringType::class
    && $boundTypeClass !== StringType::class
    && $boundTypeClass !== ConstantIntegerType::class
    && $boundTypeClass !== IntegerType::class
    && $boundTypeClass !== FloatType::class
    && $boundTypeClass !== BooleanType::class
    && $boundTypeClass !== ObjectWithoutClassType::class
    && $boundTypeClass !== ObjectType::class
    && $boundTypeClass !== ObjectShapeType::class
    && $boundTypeClass !== GenericObjectType::class
    && $boundTypeClass !== KeyOfType::class
    && $boundTypeClass !== IterableType::class
    && !$boundType instanceof UnionType
    && !$boundType instanceof IntersectionType
    && !$boundType instanceof TemplateType
    ) {
    $messages[] = RuleErrorBuilder::message(sprintf($notSupportedBoundMessage, $templateTagName, $boundType->describe(VerbosityLevel::typeOnly())))
    ->identifier('generics.notSupportedBound')
    ->build();
    }
    along with a test because of null is now supported.

@SplotyCode
Copy link
Contributor Author

This also fixes phpstan/phpstan#12894 and phpstan/phpstan#12989

@SplotyCode SplotyCode marked this pull request as draft August 29, 2025 17:57
@SplotyCode SplotyCode force-pushed the fix/nullable-templates branch 4 times, most recently from 3b94c27 to 4e21244 Compare August 29, 2025 18:37
@SplotyCode SplotyCode force-pushed the fix/nullable-templates branch from 4e21244 to 22ace72 Compare August 29, 2025 21:12
@SplotyCode SplotyCode marked this pull request as ready for review August 29, 2025 22:07
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes
Copy link
Member

This also fixes phpstan/phpstan#12894 and phpstan/phpstan#12989

This text has to be in the main PR description in order to auto-close the issues. I'll do it manually for this one.

@ondrejmirtes ondrejmirtes merged commit c33c5a1 into phpstan:2.1.x Aug 30, 2025
256 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

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.

False positive match.unhandled when using match on enum|null with generic
3 participants