Skip to content

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Sep 30, 2025

@ondrejmirtes I discovered a bug introduced by #678

When an enum has only one value, I tried to do a Union of a single type and it crash with a ShouldNotHappenException.

I added a reproducer and a fix.

@VincentLanglet VincentLanglet changed the title WIP - Bug single enum Fix PHPStan crashing with single value enum Sep 30, 2025
@VincentLanglet VincentLanglet marked this pull request as ready for review September 30, 2025 13:27
@VincentLanglet
Copy link
Contributor Author

Failures seems unrelated

$writableToPropertyType = new UnionType($enumTypes);
$writableToDatabaseType = new UnionType($enumTypes);
$writableToPropertyType = TypeCombinator::union(...$enumTypes);
$writableToDatabaseType = TypeCombinator::union(...$enumTypes);
Copy link
Member

Choose a reason for hiding this comment

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

Think of the machine and do the exact same union call only once :) Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, if you can wait 5 min for the release, I'll do it now.

@ondrejmirtes ondrejmirtes merged commit cd42b17 into phpstan:2.0.x Oct 6, 2025
35 of 37 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.

2 participants