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

Merged
韩天峰 merged 2 commits from fix-interface-impl-param-type-cross-ns into master 1 month ago
  1. 5
      src/Translator.php
  2. 62
      tests/compiler/namespace/interface-impl-param-type-cross-ns.phpt

@ -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->class
? [['kind' => 'instanceof', 'class' => $arg->class]]
Type::OBJECT => $declaredClass
? [['kind' => 'instanceof', 'class' => $declaredClass]]
: [['kind' => 'isObject']],
default => null,
};

@ -0,0 +1,62 @@
--TEST--
Cross-namespace interface implementation parameter compatibility is declaration-order independent
--FILE--
<?php
namespace A {
use B\I0;
use B\I1;
use B\I2;
abstract class Test implements I2
{
public function test(I1 $a): bool
{
return true;
}
public function testParent(I0 $a): bool
{
return true;
}
}
}
namespace B {
interface I0
{
}
interface I1 extends I0
{
}
interface I2
{
public function test(I1 $a): bool;
public function testParent(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()));
var_dump($obj->testParent(new \B\Impl1()));
echo "done\n";
}
}
?>
--EXPECT--
bool(true)
bool(true)
done
Loading…
Cancel
Save