fix(compiler): 修复声明先后影响跨命名空间接口类型校验

pull/21/head
Yurun 1 month ago
parent 559a8860a0
commit 72cbdc500a
  1. 4
      src/Translator.php
  2. 48
      tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt

@ -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,
};

@ -0,0 +1,48 @@
--TEST--
Cross-namespace interface implementation with an interface-typed parameter must not be reported as incompatible
--FILE--
<?php
namespace A {
use B\I1;
use B\I2;
abstract class Test implements I2
{
public function test(I1 $a): bool
{
return true;
}
}
}
namespace B {
interface I1
{
}
interface I2
{
public function test(I1 $a): bool;
}
class Impl1 implements I1
{
}
}
namespace {
class Concrete extends \A\Test
{
}
function main()
{
$obj = new Concrete();
var_dump($obj->test(new \B\Impl1()));
echo "done\n";
}
}
?>
--EXPECT--
bool(true)
done
Loading…
Cancel
Save