- 将 std::unsafe_cast 的类型检查逻辑重构为统一的模板函数 - 修改异常类型从 RuntimeException 为 TypeError - 更新编译器代码生成以使用新的类型转换函数 - 添加对 std::map 和 std::unordered_map 的类型转换支持 - 创建新的测试用例验证各种容器类型的 unsafe_cast 行为 - 修正现有测试用例中的异常类型断言pull/1/head
parent
7f4dee40c0
commit
5d1e8d893c
7 changed files with 73 additions and 25 deletions
@ -0,0 +1,22 @@ |
||||
--TEST-- |
||||
std array: unsafe_cast type mismatch |
||||
--FILE-- |
||||
<?php |
||||
function std_array_unsafe_ptr_type_mismatch(UnsafePtr $unsafePtr): void |
||||
{ |
||||
$array = std::unsafe_cast(std::array(native_types::type_float, 3), $unsafePtr); |
||||
} |
||||
|
||||
function main() { |
||||
$array = std::array(native_types::type_int, 3); |
||||
$ptr = std::unsafe_ptr($array); |
||||
|
||||
try { |
||||
std_array_unsafe_ptr_type_mismatch($ptr); |
||||
} catch (TypeError $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
std::unsafe_cast(): UnsafePtr type mismatch |
||||
@ -0,0 +1,22 @@ |
||||
--TEST-- |
||||
std map: unsafe_cast type mismatch |
||||
--FILE-- |
||||
<?php |
||||
function std_map_unsafe_ptr_type_mismatch(UnsafePtr $unsafePtr): void |
||||
{ |
||||
$map = std::unsafe_cast(std::map(complex_types::type_str, native_types::type_float), $unsafePtr); |
||||
} |
||||
|
||||
function main() { |
||||
$map = std::map(complex_types::type_str, native_types::type_int); |
||||
$ptr = std::unsafe_ptr($map); |
||||
|
||||
try { |
||||
std_map_unsafe_ptr_type_mismatch($ptr); |
||||
} catch (TypeError $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
std::unsafe_cast(): UnsafePtr type mismatch |
||||
@ -0,0 +1,22 @@ |
||||
--TEST-- |
||||
std unordered map: unsafe_cast type mismatch |
||||
--FILE-- |
||||
<?php |
||||
function std_unordered_map_unsafe_ptr_type_mismatch(UnsafePtr $unsafePtr): void |
||||
{ |
||||
$map = std::unsafe_cast(std::unordered_map(native_types::type_int, native_types::type_float), $unsafePtr); |
||||
} |
||||
|
||||
function main() { |
||||
$map = std::unordered_map(native_types::type_int, native_types::type_int); |
||||
$ptr = std::unsafe_ptr($map); |
||||
|
||||
try { |
||||
std_unordered_map_unsafe_ptr_type_mismatch($ptr); |
||||
} catch (TypeError $e) { |
||||
echo $e->getMessage(), "\n"; |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
std::unsafe_cast(): UnsafePtr type mismatch |
||||
Loading…
Reference in new issue