Skip to content

Commit 4e5c736

Browse files
committed
Improve error message for generic type argument validation and add test for F-bounded polymorphism diagnostics
1 parent 0c91be7 commit 4e5c736

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/Internal/Generics/TemplateManager.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ private static function bindSingleTemplateArgument(
955955
$contextPrefix = $context !== '' ? (str_ends_with($context, ':') ? $context . ' ' : $context . ' ') : ' ';
956956

957957
return ErrorFactory::createError(
958-
$contextPrefix . "Generic type argument {$expectedTypeNode} does not satisfy upper bound {$templateTag->bound} of template {$templateTag->name} in {$className}"
958+
$contextPrefix . "Generic type argument {$expectedTypeNode} does not satisfy upper bound {$boundNode} of template {$templateTag->name} in {$className}"
959959
);
960960
}
961961
}

‎tests/TypeChecking/Generics/FBoundedPolymorphismTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,5 +218,15 @@ final class FBoundImpostor extends FBoundBase
218218
$base = new FBoundDerived();
219219
})->toThrow(TypeError::class);
220220
});
221+
222+
test('reports substituted bound in diagnostic message when generic argument fails F-bound', function () {
223+
expect(function () {
224+
/** @var FBoundSortedList<FBoundPlain> $list */
225+
$list = new FBoundSortedList();
226+
})->toThrow(
227+
TypeError::class,
228+
'Generic type argument ' . FBoundPlain::class . ' does not satisfy upper bound ' . FBoundComparable::class . '<' . FBoundPlain::class . '> of template T in ' . FBoundSortedList::class
229+
);
230+
});
221231
});
222232
});

0 commit comments

Comments
 (0)