- 在 CompilerBase 中添加 IntersectionType 的引入和处理逻辑 - 更新 upgradeToFullyQualifiedName 方法以处理交集类型 - 修改复杂类型处理逻辑,将交集类型统一按 mixed/var 处理并在运行时进行 typeCheck - 在 Preprocessor 中添加对交集类型的参数和返回值检查支持 - 扩展 TypeCheckGenerator 以支持交集类型的类型检查代码生成 - 添加交集类型参数和返回值的运行时检查测试用例 - 实现交集类型的字符串表示转换功能 - 添加 allOf 类型条件生成器以处理多个类型约束组合pull/5/head
parent
04610c5897
commit
a0c9591e81
6 changed files with 243 additions and 61 deletions
@ -0,0 +1,34 @@ |
||||
--TEST-- |
||||
Intersection type: parameter runtime type checking |
||||
--FILE-- |
||||
<?php |
||||
|
||||
interface IA {} |
||||
interface IB {} |
||||
|
||||
class Both implements IA, IB {} |
||||
class OnlyA implements IA {} |
||||
|
||||
function expect_both(IA&IB $value): void { |
||||
var_dump(get_class($value)); |
||||
} |
||||
|
||||
function main() { |
||||
expect_both(new Both()); |
||||
|
||||
$errors = []; |
||||
|
||||
try { |
||||
expect_both(new OnlyA()); |
||||
} catch (\TypeError $e) { |
||||
$errors[] = $e->getMessage(); |
||||
} |
||||
|
||||
foreach ($errors as $err) { |
||||
var_dump($err); |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(4) "Both" |
||||
string(71) "expect_both(): Argument #1 ($value) must be of type IA&IB, object given" |
||||
@ -0,0 +1,34 @@ |
||||
--TEST-- |
||||
Intersection type: return runtime type checking |
||||
--FILE-- |
||||
<?php |
||||
|
||||
interface IA {} |
||||
interface IB {} |
||||
|
||||
class Both implements IA, IB {} |
||||
class OnlyA implements IA {} |
||||
|
||||
function return_both(object $value): IA&IB { |
||||
return $value; |
||||
} |
||||
|
||||
function main() { |
||||
var_dump(get_class(return_both(new Both()))); |
||||
|
||||
$errors = []; |
||||
|
||||
try { |
||||
return_both(new OnlyA()); |
||||
} catch (\TypeError $e) { |
||||
$errors[] = $e->getMessage(); |
||||
} |
||||
|
||||
foreach ($errors as $err) { |
||||
var_dump($err); |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(4) "Both" |
||||
string(63) "return_both(): Return value must be of type IA&IB, object given" |
||||
Loading…
Reference in new issue