Skip to content

Commit

Permalink
Merge pull request #8364 from kkmuffme/add-but-to-differentiate-error…
Browse files Browse the repository at this point in the history
…s-invalidargument

add ", but" for InvalidArgument error message where a type is provided
  • Loading branch information
orklah committed Aug 3, 2022
2 parents 6998fab + d2be169 commit 1ef3851
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
Expand Up @@ -181,7 +181,7 @@ public static function checkArgumentMatches(
IssueBuffer::maybeAdd(
new InvalidLiteralArgument(
'Argument ' . ($argument_offset + 1) . ' of ' . $cased_method_id
. ' expects a non-literal value, ' . $arg_value_type->getId() . ' provided',
. ' expects a non-literal value, but ' . $arg_value_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $arg->value),
$cased_method_id
),
Expand Down Expand Up @@ -976,7 +976,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new MixedArgumentTypeCoercion(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() .
', parent type ' . $input_type->getId() . ' provided',
', but parent type ' . $input_type->getId() . ' provided',
$arg_location,
$cased_method_id,
$origin_location
Expand All @@ -987,7 +987,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new ArgumentTypeCoercion(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() .
', parent type ' . $input_type->getId() . ' provided',
', but parent type ' . $input_type->getId() . ' provided',
$arg_location,
$cased_method_id
),
Expand All @@ -1000,7 +1000,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new ImplicitToStringCast(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' .
$param_type->getId() . ', ' . $input_type->getId() . ' provided with a __toString method',
$param_type->getId() . ', but ' . $input_type->getId() . ' provided with a __toString method',
$arg_location
),
$statements_analyzer->getSuppressedIssues()
Expand All @@ -1022,7 +1022,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new InvalidScalarArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' .
$param_type->getId() . ', ' . $type . ' provided',
$param_type->getId() . ', but ' . $type . ' provided',
$arg_location,
$cased_method_id
),
Expand All @@ -1033,7 +1033,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new PossiblyInvalidArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() .
', possibly different type ' . $type . ' provided',
', but possibly different type ' . $type . ' provided',
$arg_location,
$cased_method_id
),
Expand All @@ -1043,7 +1043,7 @@ public static function verifyType(
IssueBuffer::maybeAdd(
new InvalidArgument(
'Argument ' . ($argument_offset + 1) . $method_identifier . ' expects ' . $param_type->getId() .
', ' . $type . ' provided',
', but ' . $type . ' provided',
$arg_location,
$cased_method_id
),
Expand Down
Expand Up @@ -893,7 +893,8 @@ private static function checkClosureTypeArgs(
IssueBuffer::maybeAdd(
new MixedArgumentTypeCoercion(
'Parameter ' . ($i + 1) . ' of closure passed to function ' . $method_id . ' expects ' .
$closure_param_type->getId() . ', parent type ' . $input_type->getId() . ' provided',
$closure_param_type->getId() .
', but parent type ' . $input_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $closure_arg),
$method_id
),
Expand All @@ -903,7 +904,8 @@ private static function checkClosureTypeArgs(
IssueBuffer::maybeAdd(
new ArgumentTypeCoercion(
'Parameter ' . ($i + 1) . ' of closure passed to function ' . $method_id . ' expects ' .
$closure_param_type->getId() . ', parent type ' . $input_type->getId() . ' provided',
$closure_param_type->getId() .
', but parent type ' . $input_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $closure_arg),
$method_id
),
Expand All @@ -923,7 +925,7 @@ private static function checkClosureTypeArgs(
IssueBuffer::maybeAdd(
new InvalidScalarArgument(
'Parameter ' . ($i + 1) . ' of closure passed to function ' . $method_id . ' expects ' .
$closure_param_type->getId() . ', ' . $input_type->getId() . ' provided',
$closure_param_type->getId() . ', but ' . $input_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $closure_arg),
$method_id
),
Expand All @@ -933,7 +935,7 @@ private static function checkClosureTypeArgs(
IssueBuffer::maybeAdd(
new PossiblyInvalidArgument(
'Parameter ' . ($i + 1) . ' of closure passed to function ' . $method_id . ' expects '
. $closure_param_type->getId() . ', possibly different type '
. $closure_param_type->getId() . ', but possibly different type '
. $input_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $closure_arg),
$method_id
Expand All @@ -943,7 +945,7 @@ private static function checkClosureTypeArgs(
} elseif (IssueBuffer::accepts(
new InvalidArgument(
'Parameter ' . ($i + 1) . ' of closure passed to function ' . $method_id . ' expects ' .
$closure_param_type->getId() . ', ' . $input_type->getId() . ' provided',
$closure_param_type->getId() . ', but ' . $input_type->getId() . ' provided',
new CodeLocation($statements_analyzer->getSource(), $closure_arg),
$method_id
),
Expand Down
2 changes: 1 addition & 1 deletion tests/ClosureTest.php
Expand Up @@ -1149,7 +1149,7 @@ function takesB(B $_b) : void {}
takesA($getAButReallyB());
takesB($getAButReallyB());',
'error_message' => 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:28 - Argument 1 of takesB expects B, parent type A provided',
'error_message' => 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:28 - Argument 1 of takesB expects B, but parent type A provided',
],
'closureByRefUseToMixed' => [
'<?php
Expand Down
2 changes: 1 addition & 1 deletion tests/ReturnTypeTest.php
Expand Up @@ -1500,7 +1500,7 @@ function($iter) use ($predicate) {
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:54 - Argument 1 expects T:fn-map as mixed, int provided',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:13:54 - Argument 1 expects T:fn-map as mixed, but int provided',
],
'cannotInferReturnClosureWithDifferentReturnTypes' => [
'<?php
Expand Down
4 changes: 2 additions & 2 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -3936,7 +3936,7 @@ public function __construct(callable $closure)
type($closure);
}
}',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:20:34 - Argument 1 of type expects string, callable(State):(T:AlmostFooMap as mixed)&Foo provided',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:20:34 - Argument 1 of type expects string, but callable(State):(T:AlmostFooMap as mixed)&Foo provided',
],
'templateWithNoReturn' => [
'<?php
Expand Down Expand Up @@ -4118,7 +4118,7 @@ class CharacterRow extends Row {}
$mario = new CharacterRow(["id" => 5, "name" => "Mario", "height" => 3.5]);
$mario->ame = "Luigi";',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:47:29 - Argument 1 of CharacterRow::__set expects "height"|"id"|"name", "ame" provided',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:47:29 - Argument 1 of CharacterRow::__set expects "height"|"id"|"name", but "ame" provided',
],
'specialiseTypeBeforeReturning' => [
'<?php
Expand Down
4 changes: 2 additions & 2 deletions tests/TypeReconciliation/TypeTest.php
Expand Up @@ -1519,7 +1519,7 @@ class C extends A {}
function takesB(B $i): void {}',
'error_message' => 'ArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:14:32 - Argument 1 of takesB expects B,'
. ' parent type A&static provided',
. ' but parent type A&static provided',
],
'intersectionTypeInterfaceCheckAfterInstanceof' => [
'<?php
Expand All @@ -1540,7 +1540,7 @@ public static function getFoo(): void {
interface I {}
function takesI(I $i): void {}',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:12:32 - Argument 1 of takesI expects I, A&static provided',
'error_message' => 'InvalidArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:12:32 - Argument 1 of takesI expects I, but A&static provided',
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UnusedVariableTest.php
Expand Up @@ -3451,7 +3451,7 @@ function takesArray($a) : void {
$arr = [$a];
takesArrayOfString($arr);
}',
'error_message' => 'MixedArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:12:44 - Argument 1 of takesArrayOfString expects array<array-key, string>, parent type array{mixed} provided. Consider improving the type at src' . DIRECTORY_SEPARATOR . 'somefile.php:10:41'
'error_message' => 'MixedArgumentTypeCoercion - src' . DIRECTORY_SEPARATOR . 'somefile.php:12:44 - Argument 1 of takesArrayOfString expects array<array-key, string>, but parent type array{mixed} provided. Consider improving the type at src' . DIRECTORY_SEPARATOR . 'somefile.php:10:41'
],
'warnAboutUnusedVariableInTryReassignedInCatch' => [
'<?php
Expand Down

0 comments on commit 1ef3851

Please sign in to comment.