From 72423b821fd08baccf21aa803908c86d22c336f8 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Mon, 27 Jul 2026 11:48:23 +0300 Subject: [PATCH 1/2] Add test case --- tests/return-from-constructor.phpt | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/return-from-constructor.phpt diff --git a/tests/return-from-constructor.phpt b/tests/return-from-constructor.phpt new file mode 100644 index 0000000..fe8e291 --- /dev/null +++ b/tests/return-from-constructor.phpt @@ -0,0 +1,32 @@ +--TEST-- +https://github.com/antecedent/patchwork/issues/213 + +--FILE-- + +===DONE=== + +--EXPECT-- +Patchwork\Exceptions\NonNullToVoid +===DONE=== From f9be20cd5bc0f91f8064039cbff119d03451f874 Mon Sep 17 00:00:00 2001 From: Ignas Rudaitis Date: Mon, 27 Jul 2026 11:49:00 +0300 Subject: [PATCH 2/2] Treat constructors as void-typed --- src/CodeManipulation/Actions/Generic.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CodeManipulation/Actions/Generic.php b/src/CodeManipulation/Actions/Generic.php index fb0ea54..f95a598 100644 --- a/src/CodeManipulation/Actions/Generic.php +++ b/src/CodeManipulation/Actions/Generic.php @@ -78,6 +78,10 @@ function prependCodeToFunctions($code, $typedVariants = array(), $fillArgRefs = function getDeclaredReturnType(Source $s, $function) { $parenthesis = $s->next(LEFT_ROUND, $function); + $name = $s->next(T_STRING, $function); + if ($name < $parenthesis && $s->read($name) === '__construct') { + return 'void'; + } $next = $s->skip(Source::junk(), $s->match($parenthesis)); if ($s->is(T_USE, $next)) { $next = $s->skip(Source::junk(), $s->match($s->next(LEFT_ROUND, $next)));