Skip to content

Commit

Permalink
Improve inference of constant() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 14, 2020
1 parent b09869b commit adc6589
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,27 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
} else {
$context->check_consts = false;
}
} elseif ($function->parts === ['constant']) {
if ($first_arg) {
$fq_const_name = StatementsAnalyzer::getConstName(
$first_arg->value,
$statements_analyzer->node_data,
$codebase,
$statements_analyzer->getAliases()
);

if ($fq_const_name !== null) {
$const_type = $statements_analyzer->getConstType(
$fq_const_name,
true,
$context
);

$statements_analyzer->node_data->setType($stmt, $const_type);
}
} else {
$context->check_consts = false;
}
} elseif ($first_arg
&& $function_id
&& strpos($function_id, 'is_') === 0
Expand Down
5 changes: 5 additions & 0 deletions tests/ConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ function test($value): void {
test(Test::VALUES);'
],
'resolveConstantFetchViaFunction' => [
'<?php
const FOO = 1;
echo \constant("FOO");'
],
];
}

Expand Down

0 comments on commit adc6589

Please sign in to comment.