test(compiler): cover cross-namespace parameter variance

pull/21/head
韩天峰 1 month ago
parent 72cbdc500a
commit e231aa2404
  1. 5
      src/Translator.php
  2. 18
      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->declaredClass
? [['kind' => 'instanceof', 'class' => $arg->declaredClass]]
Type::OBJECT => $declaredClass
? [['kind' => 'instanceof', 'class' => $declaredClass]]
: [['kind' => 'isObject']],
default => null,
};

@ -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--
<?php
namespace A {
use B\I0;
use B\I1;
use B\I2;
@ -12,17 +13,28 @@ namespace A {
{
return true;
}
public function testParent(I0 $a): bool
{
return true;
}
}
}
namespace B {
interface I1
interface I0
{
}
interface I1 extends I0
{
}
interface I2
{
public function test(I1 $a): bool;
public function testParent(I1 $a): bool;
}
class Impl1 implements I1
@ -39,10 +51,12 @@ namespace {
{
$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