Skip to content
Permalink
Browse files

Fix #2574 - remove assertions after increment

  • Loading branch information
muglug committed Jan 9, 2020
1 parent bd7f342 commit bd9142f1317c1d3138a9aa94b7590036ddd43a84
@@ -283,7 +283,7 @@ public static function analyze(
$assign_value_type->by_ref = true;
}

// removes dependennt vars from $context
// removes dependent vars from $context
$context->removeDescendents(
$array_var_id,
$context->vars_in_scope[$array_var_id],
@@ -978,6 +978,34 @@ public static function analyzeAssignmentOperation(
}
}

if ($array_var_id && isset($context->vars_in_scope[$array_var_id])) {
if ($result_type && $context->vars_in_scope[$array_var_id]->by_ref) {
$result_type->by_ref = true;
}

// removes dependent vars from $context
$context->removeDescendents(
$array_var_id,
$context->vars_in_scope[$array_var_id],
$result_type,
$statements_analyzer
);
} else {
$root_var_id = ExpressionAnalyzer::getRootVarId(
$stmt->var,
$statements_analyzer->getFQCLN(),
$statements_analyzer
);

if ($root_var_id && isset($context->vars_in_scope[$root_var_id])) {
$context->removeVarFromConflictingClauses(
$root_var_id,
$context->vars_in_scope[$root_var_id],
$statements_analyzer
);
}
}

if ($stmt->var instanceof PhpParser\Node\Expr\ArrayDimFetch) {
ArrayAssignmentAnalyzer::analyze(
$statements_analyzer,
@@ -412,6 +412,14 @@ public static function analyze(
);
$context->unreferenced_vars[$var_id] = [$location->getHash() => $location];
}

// removes dependent vars from $context
$context->removeDescendents(
$var_id,
$context->vars_in_scope[$var_id],
$return_type,
$statements_analyzer
);
}
} else {
$statements_analyzer->node_data->setType($stmt, Type::getMixed());
@@ -704,6 +704,48 @@ function b($impl) : void {
}
}'
],
'invalidateAfterPostIncrement' => [
'<?php
/**
* @param array<int, int> $tokens
*/
function propertyInUse(array $tokens, int $i): bool {
if ($tokens[$i] !== 1) {
return false;
}
$i++;
if ($tokens[$i] !== 2) {}
return false;
}'
],
'invalidateAfterAssignOp' => [
'<?php
/**
* @param array<int, int> $tokens
*/
function propertyInUse(array $tokens, int $i): bool {
if ($tokens[$i] !== 1) {
return false;
}
$i += 1;
if ($tokens[$i] !== 2) {}
return false;
}'
],
'invalidateAfterAssign' => [
'<?php
/**
* @param array<int, int> $tokens
*/
function propertyInUse(array $tokens, int $i): bool {
if ($tokens[$i] !== 1) {
return false;
}
$i = $i + 1;
if ($tokens[$i] !== 2) {}
return false;
}'
],
];
}

0 comments on commit bd9142f

Please sign in to comment.
You can’t perform that action at this time.