修复 while do...while和if中的判断是赋值导致的C++编译警告的问题 #3

Merged
韩天峰 merged 2 commits from condition_assign into master 2 months ago
  1. 8
      src/Php/CompilerBase.php
  2. 12
      tests/aot/basic/condition-assign.phpt

@ -1430,6 +1430,10 @@ class CompilerBase extends \PhpAot\Core\Translator
$this->appendCapturedStmtLines($code, $afterStmts);
$condExpr = $tmpVar;
}
if ($cond instanceof Expr\Assign) {
$condExpr = '(' . $condExpr . ')';
}
$code .= $openPrefix . '(' . $condExpr . ') {' . PHP_EOL;
return $code;
}
@ -4109,10 +4113,8 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($tail !== '') {
$code .= $this->getIndent() . '} else {' . PHP_EOL;
$code .= $tail;
$code .= $this->getIndent() . '}';
} else {
$code .= $this->getIndent() . '}';
}
$code .= $this->getIndent() . '}';
return $code;
};

@ -0,0 +1,12 @@
--TEST--
condition assign
--FILE--
<?php
function main() {
if ($value = true) {
echo "success";
}
}
?>
--EXPECT--
success
Loading…
Cancel
Save