parent
81f298d655
commit
cff557b649
4 changed files with 133 additions and 22 deletions
@ -0,0 +1,57 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* This file is part of TypePHP(AOT). |
||||||
|
* |
||||||
|
* @link https://www.swoole.com/aot/ |
||||||
|
* @contact service@swoole.com |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace { |
||||||
|
use function abs as absolute; |
||||||
|
|
||||||
|
function inferredAbsInt(int $value): void |
||||||
|
{ |
||||||
|
$result = abs($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
|
||||||
|
function inferredAliasedAbsInt(int $value): void |
||||||
|
{ |
||||||
|
$result = absolute($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
|
||||||
|
function inferredLocalAbsInt(): void |
||||||
|
{ |
||||||
|
$value = PHP_INT_MIN; |
||||||
|
$result = abs($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
|
||||||
|
function inferredAbsFloat(float $value): void |
||||||
|
{ |
||||||
|
$result = abs($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
|
||||||
|
function inferredAbsDynamic(mixed $value): void |
||||||
|
{ |
||||||
|
$result = abs($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
namespace AbsInferenceNamespace { |
||||||
|
function inferredNamespacedAbs(int $value): void |
||||||
|
{ |
||||||
|
// A runtime-provided namespaced function may shadow global abs(). |
||||||
|
$result = abs($value); |
||||||
|
var_dump($result); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
namespace { |
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* This file is part of TypePHP(AOT). |
||||||
|
* |
||||||
|
* @link https://www.swoole.com/aot/ |
||||||
|
* @contact service@swoole.com |
||||||
|
*/ |
||||||
|
|
||||||
|
use TypePhp\CompilerTest; |
||||||
|
|
||||||
|
/** |
||||||
|
* @internal |
||||||
|
* @coversNothing |
||||||
|
*/ |
||||||
|
final class AbsTypeInferenceTest extends BaseTest |
||||||
|
{ |
||||||
|
public function testResultStorageFollowsTheStaticallySelectedOverload(): void |
||||||
|
{ |
||||||
|
global $translator; |
||||||
|
|
||||||
|
$compiler = CompilerTest::create(TYPEPHP_ROOT_PATH); |
||||||
|
$translator = $compiler; |
||||||
|
$source = TYPEPHP_ROOT_PATH . '/phpunit/code/abs-type-inference.php'; |
||||||
|
$compiler->addFiles([$source]); |
||||||
|
$compiler->prepareFile($source); |
||||||
|
$code = file_get_contents($compiler->convertFile($source)); |
||||||
|
|
||||||
|
self::assertIsString($code); |
||||||
|
self::assertSame(3, substr_count($code, 'php::Int result = 0;')); |
||||||
|
self::assertSame(1, substr_count($code, 'php::Float result = 0;')); |
||||||
|
self::assertSame(2, substr_count($code, 'php::Var result;')); |
||||||
|
self::assertSame(5, substr_count($code, 'php::fn::abs(')); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue