From 72cbdc500a1805dda5180ef0e7c714d47afcba6a Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 15 Jul 2026 19:20:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(compiler):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E5=85=88=E5=90=8E=E5=BD=B1=E5=93=8D=E8=B7=A8?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E6=8E=A5=E5=8F=A3=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Translator.php | 4 +- .../interface-impl-param-type-cross-ns.phpt | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt diff --git a/src/Translator.php b/src/Translator.php index 676618a3..ce370f1e 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -3249,8 +3249,8 @@ CODE; Type::STR => [['kind' => 'isString']], Type::ARRAY => [['kind' => 'isArray']], Type::RESOURCE => [['kind' => 'isResource']], - Type::OBJECT => $arg->class - ? [['kind' => 'instanceof', 'class' => $arg->class]] + Type::OBJECT => $arg->declaredClass + ? [['kind' => 'instanceof', 'class' => $arg->declaredClass]] : [['kind' => 'isObject']], default => null, }; diff --git a/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt b/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt new file mode 100644 index 00000000..acaec9e6 --- /dev/null +++ b/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt @@ -0,0 +1,48 @@ +--TEST-- +Cross-namespace interface implementation with an interface-typed parameter must not be reported as incompatible +--FILE-- +test(new \B\Impl1())); + echo "done\n"; + } +} +?> +--EXPECT-- +bool(true) +done From e231aa2404f2b1eced506e825484c6fdb98abab4 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sun, 19 Jul 2026 10:58:13 +0800 Subject: [PATCH 2/2] test(compiler): cover cross-namespace parameter variance --- src/Translator.php | 5 +++-- .../interface-impl-param-type-cross-ns.phpt | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Translator.php b/src/Translator.php index ce370f1e..e7c3838a 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -3242,6 +3242,7 @@ CODE; return $arg->typeCheck; } + $declaredClass = $arg->declaredClass ?: $arg->class; return match ($arg->type) { Type::INT => [['kind' => 'isInt']], Type::FLOAT => [['kind' => 'isFloat']], @@ -3249,8 +3250,8 @@ CODE; Type::STR => [['kind' => 'isString']], Type::ARRAY => [['kind' => 'isArray']], Type::RESOURCE => [['kind' => 'isResource']], - Type::OBJECT => $arg->declaredClass - ? [['kind' => 'instanceof', 'class' => $arg->declaredClass]] + Type::OBJECT => $declaredClass + ? [['kind' => 'instanceof', 'class' => $declaredClass]] : [['kind' => 'isObject']], default => null, }; diff --git a/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt b/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt index acaec9e6..535212a7 100644 --- a/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt +++ b/tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt @@ -1,8 +1,9 @@ --TEST-- -Cross-namespace interface implementation with an interface-typed parameter must not be reported as incompatible +Cross-namespace interface implementation parameter compatibility is declaration-order independent --FILE-- test(new \B\Impl1())); + var_dump($obj->testParent(new \B\Impl1())); echo "done\n"; } } ?> --EXPECT-- bool(true) +bool(true) done