diff --git a/src/Analyser/ExprHandler/NewHandler.php b/src/Analyser/ExprHandler/NewHandler.php index 1ffcad58620..61244aa9fbe 100644 --- a/src/Analyser/ExprHandler/NewHandler.php +++ b/src/Analyser/ExprHandler/NewHandler.php @@ -464,7 +464,7 @@ private function getConstructorThrowPoint(MethodReflection $constructorReflectio } } elseif ($this->implicitThrows) { if (!$context->isInThrow() || !$constructorReflection->getDeclaringClass()->is(Throwable::class)) { - return InternalThrowPoint::createImplicit($scope, $methodCall); + return InternalThrowPoint::createImplicit($scope, $new); } } diff --git a/src/Turbo/TurboExtensionEnabler.php b/src/Turbo/TurboExtensionEnabler.php index a0c9829a03e..03b1e80d4d7 100644 --- a/src/Turbo/TurboExtensionEnabler.php +++ b/src/Turbo/TurboExtensionEnabler.php @@ -33,7 +33,7 @@ final class TurboExtensionEnabler { - public const EXPECTED_EXTENSION_VERSION = '6351afb'; + public const EXPECTED_EXTENSION_VERSION = '12acf37'; private static bool $active = false; diff --git a/tests/PHPStan/Rules/Methods/UnusedMethodParametersRuleTest.php b/tests/PHPStan/Rules/Methods/UnusedMethodParametersRuleTest.php index 75994dcbe65..1990463fe46 100644 --- a/tests/PHPStan/Rules/Methods/UnusedMethodParametersRuleTest.php +++ b/tests/PHPStan/Rules/Methods/UnusedMethodParametersRuleTest.php @@ -44,6 +44,11 @@ public function testParameterReadOnlyInCatchOfOverridingThrows(): void $this->analyse([__DIR__ . '/data/unused-method-parameters-overriding-throws.php'], []); } + public function testParameterReadOnlyInCatchOfImplicitConstructorThrows(): void + { + $this->analyse([__DIR__ . '/data/unused-method-parameters-implicit-constructor-throws.php'], []); + } + public function testParameterCapturedByReference(): void { $this->analyse([__DIR__ . '/data/unused-method-parameters-by-ref-use.php'], [ diff --git a/tests/PHPStan/Rules/Methods/data/unused-method-parameters-implicit-constructor-throws.php b/tests/PHPStan/Rules/Methods/data/unused-method-parameters-implicit-constructor-throws.php new file mode 100644 index 00000000000..127f6399c99 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/unused-method-parameters-implicit-constructor-throws.php @@ -0,0 +1,46 @@ += 8.0 + +namespace UnusedMethodParametersImplicitConstructorThrows; + +class Foo +{ + + public function __construct(string $value) + { + if ($value === '') { + throw new \InvalidArgumentException('Empty value'); + } + } + +} + +class Bar +{ + + private function readOnlyInCatch(string $value, string $param): ?Foo + { + try { + return new Foo($value); + } catch (\Throwable $e) { + echo $param; + return null; + } + } + + private function readOnlyInCatchOfException(string $value, string $param): ?Foo + { + try { + return new Foo($value); + } catch (\Exception $e) { + echo $param; + return null; + } + } + + public function doBar(): void + { + $this->readOnlyInCatch('x', 'y'); + $this->readOnlyInCatchOfException('x', 'y'); + } + +} diff --git a/turbo-ext/src/NewHandler.cpp b/turbo-ext/src/NewHandler.cpp index bddea63b684..42e18fc70a4 100644 --- a/turbo-ext/src/NewHandler.cpp +++ b/turbo-ext/src/NewHandler.cpp @@ -923,7 +923,7 @@ class NewHandler implicit = !isThrowable; } if (implicit) { - return pt_internal_throw_point_create_implicit(scope, methodCall.raw()); + return pt_internal_throw_point_create_implicit(scope, new_); } }