- Add acceptsCallable property to ArgInfo entity to track callable type acceptance - Implement logic to detect when function parameters accept callable types - Add normalization of bare function callable arguments to string representation - Create helper methods to check if types contain callable declarations - Add resolution logic for bare identifier function names in callable context - Update native class support to set acceptsCallable flag based on type checking - Modify preprocessor to populate acceptsCallable field during argument parsing - Remove deprecated typeDeclContainsCallable method and consolidate logic - Add comprehensive test coverage for baremaster
parent
3bb73de645
commit
9d68d2803c
10 changed files with 378 additions and 29 deletions
@ -0,0 +1,15 @@ |
||||
<?php |
||||
|
||||
function cube($n) |
||||
{ |
||||
return ($n * $n * $n); |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$a = [1, 2, 3, 4, 5]; |
||||
$b = array_map(cube, $a); |
||||
print_r($b); |
||||
} |
||||
|
||||
|
||||
@ -0,0 +1,77 @@ |
||||
--TEST-- |
||||
Ordinary constants are case-sensitive and magic constants are case-insensitive |
||||
--FILE-- |
||||
<?php |
||||
namespace ConstantCase { |
||||
const ExactName = 'exact'; |
||||
|
||||
trait MagicTrait |
||||
{ |
||||
public function traitNameMatches(): bool |
||||
{ |
||||
return __TrAiT__ === __TRAIT__; |
||||
} |
||||
} |
||||
|
||||
class MagicScope |
||||
{ |
||||
use MagicTrait; |
||||
|
||||
public function namesMatch(): array |
||||
{ |
||||
return [ |
||||
__ClAsS__ === __CLASS__, |
||||
__FuNcTiOn__ === __FUNCTION__, |
||||
__MeThOd__ === __METHOD__, |
||||
__NaMeSpAcE__ === __NAMESPACE__, |
||||
]; |
||||
} |
||||
} |
||||
|
||||
function functionNameMatches(): bool |
||||
{ |
||||
return __FuNcTiOn__ === __FUNCTION__; |
||||
} |
||||
} |
||||
|
||||
namespace { |
||||
function main(): void |
||||
{ |
||||
var_dump(\ConstantCase\ExactName); |
||||
var_dump(\constantcase\ExactName); |
||||
try { |
||||
var_dump(\ConstantCase\exactname); |
||||
} catch (\Error $error) { |
||||
echo "ordinary constant is case-sensitive\n"; |
||||
} |
||||
|
||||
var_dump(__FiLe__ === __FILE__); |
||||
var_dump(__DiR__ === __DIR__); |
||||
var_dump(is_int(__LiNe__)); |
||||
var_dump(__NaMeSpAcE__ === __NAMESPACE__); |
||||
var_dump(\ConstantCase\functionNameMatches()); |
||||
var_dump((new \ConstantCase\MagicScope())->namesMatch()); |
||||
var_dump((new \ConstantCase\MagicScope())->traitNameMatches()); |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(5) "exact" |
||||
string(5) "exact" |
||||
ordinary constant is case-sensitive |
||||
bool(true) |
||||
bool(true) |
||||
bool(true) |
||||
bool(true) |
||||
bool(true) |
||||
array(4) { |
||||
[0]=> |
||||
bool(true) |
||||
[1]=> |
||||
bool(true) |
||||
[2]=> |
||||
bool(true) |
||||
[3]=> |
||||
bool(true) |
||||
} |
||||
bool(true) |
||||
@ -0,0 +1,86 @@ |
||||
--TEST-- |
||||
Bare function names are resolved only for callable parameters |
||||
--FILE-- |
||||
<?php |
||||
namespace BareCallable\Library { |
||||
function triple(int $value): int |
||||
{ |
||||
return $value * 3; |
||||
} |
||||
} |
||||
|
||||
namespace BareCallable\Application { |
||||
use function BareCallable\Library\triple as imported_triple; |
||||
|
||||
function apply(callable $callback, int $value): int |
||||
{ |
||||
return $callback($value); |
||||
} |
||||
|
||||
function local_double(int $value): int |
||||
{ |
||||
return $value * 2; |
||||
} |
||||
|
||||
function run(): void |
||||
{ |
||||
var_dump(array_map(local_double, [1, 2, 3])); |
||||
var_dump(array_map(callback: local_double, array: [4])); |
||||
var_dump(apply(imported_triple, 4)); |
||||
var_dump(array_map(\strlen, ['a', 'abcd'])); |
||||
|
||||
try { |
||||
$notACallableArgument = local_double; |
||||
} catch (\Error $error) { |
||||
echo "constant rules preserved\n"; |
||||
} |
||||
} |
||||
} |
||||
|
||||
namespace { |
||||
const cube = 'square'; |
||||
|
||||
function cube(int $value): int |
||||
{ |
||||
return $value * $value * $value; |
||||
} |
||||
|
||||
function square(int $value): int |
||||
{ |
||||
return $value * $value; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
BareCallable\Application\run(); |
||||
var_dump(array_map(cube, [2, 3])); |
||||
} |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(3) { |
||||
[0]=> |
||||
int(2) |
||||
[1]=> |
||||
int(4) |
||||
[2]=> |
||||
int(6) |
||||
} |
||||
array(1) { |
||||
[0]=> |
||||
int(8) |
||||
} |
||||
int(12) |
||||
array(2) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(4) |
||||
} |
||||
constant rules preserved |
||||
array(2) { |
||||
[0]=> |
||||
int(4) |
||||
[1]=> |
||||
int(9) |
||||
} |
||||
Loading…
Reference in new issue