Repository navigation
fix(types): a literal class name can be identical to a template class-string - #14365
Merged
orklah merged 3 commits intoNov 23, 2026
Merged
Conversation
…-string vimeo#14271 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
✅ Performance: unchanged · Types: unchanged
How to read this table
head 9a9aa62 · base 28e192b (merge-base) · workflow run |
orklah
requested changes
Nov 21, 2026
orklah
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, the fix is in the right place. Two changes:
- The
TTemplateParamClass→new TClassString($as, $as_type)rewrite isn't needed:canLiteralNameBeClassString()already handles aTTemplateParamClassagainst its bound (BinaryOpAnalyzerpasses it in as is forInvalidStringClass). Dropping the exclusion and passing$type1_part/$type2_partunchanged gives the same results on bounded, interface, nested (T of U) and class templates, so the rewrite and its comment can go:
if (($type1_part instanceof TClassString || $type1_part instanceof TDependentGetClass)
&& $type2_part::class === TLiteralString::class
) {
return ClassLikeStringComparator::canLiteralNameBeClassString(
$codebase,
$type2_part,
$type1_part,
$allow_interface_equality,
);
}(and the same for the mirrored branch).
- Both tests use
@template T of object, where the bound plays no role: they'd still pass if the bound were ignored. Please add a bounded case, e.g.:
'boundedTemplateClassStringIsComparedWithASubclassName' => [
'code' => '<?php
abstract class Base {}
final class Child extends Base {}
/**
* @template T of Base
* @param class-string<T> $name
*/
function isChild(string $name): bool {
return $name === "Child";
}',
'assertions' => [],
'ignored_issues' => ['InvalidStringClass'],
],'boundedTemplateClassStringIsNeverAnUnrelatedClass' => [
'code' => '<?php
abstract class Base {}
final class Other {}
/**
* @template T of Base
* @param class-string<T> $name
*/
function isOther(string $name): bool {
return $name === "Other";
}',
'error_message' => 'DocblockTypeContradiction',
],…d, with bounded cases vimeo#14271 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@orklah thanks, both done in 55a4eaf:
CI is green apart from |
Collaborator
|
Thanks, both points are addressed and this is ready to merge, but it now conflicts with master after today's merges. Could you merge master (keeping both sides)? I'll merge it once CI is green. |
# Conflicts: # tests/ClassLikeStringTest.php
orklah
approved these changes
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A literal class name compared with a template
class-string<T>is reported asDocblockTypeContradiction, although the template can stand for that class.Before
After
A class name that does not exist is still reported (new test).
Fixes #14271