Skip to content

Commit

Permalink
Merge pull request #2197 from zephir-lang/#2186-null-strict-check
Browse files Browse the repository at this point in the history
#2186 - Fix `null` strict check
  • Loading branch information
Jeckerson authored Apr 8, 2021
2 parents 295f9bb + ae55884 commit 006b504
Show file tree
Hide file tree
Showing 32 changed files with 164 additions and 128 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org).
- Fixed default value of nullable string parameter [#2180](https://github.com/zephir-lang/zephir/issues/2180)
- Fixed cast of `string` to `int` and `float` [#828](https://github.com/zephir-lang/zephir/issues/828)
- Fix `uint` cast to `unsigned int` in function params [#812](https://github.com/zephir-lang/zephir/issues/812)
- Fixed `null` strict check when variable is `string` type [#2186](https://github.com/zephir-lang/zephir/issues/2186)

## [0.13.1] - 2021-03-31
### Added
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/AddOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
class AddOperator extends ArithmeticalBaseOperator
{
protected $operator = '+';
protected string $operator = '+';

protected $bitOperator = '|';
protected string $bitOperator = '|';

protected $zvalOperator = 'zephir_add_function';
protected string $zvalOperator = 'zephir_add_function';
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class ArithmeticalBaseOperator extends BaseOperator
{
protected $literalOnly = true;
protected bool $literalOnly = true;

/**
* This tries to perform arithmetical operations.
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/DivOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
class DivOperator extends ArithmeticalBaseOperator
{
protected $operator = '/';
protected string $operator = '/';

protected $bitOperator = '-';
protected string $bitOperator = '-';

protected $zvalOperator = 'div_function';
protected string $zvalOperator = 'div_function';

/**
* Compiles the arithmetical division operation.
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/ModOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
class ModOperator extends ArithmeticalBaseOperator
{
protected $operator = '%';
protected string $operator = '%';

protected $bitOperator = '-';
protected string $bitOperator = '-';

protected $zvalOperator = 'mod_function';
protected string $zvalOperator = 'mod_function';

/**
* Compiles the arithmetical modulus operation.
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/MulOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
class MulOperator extends ArithmeticalBaseOperator
{
protected $operator = '*';
protected string $operator = '*';

protected $bitOperator = '+';
protected string $bitOperator = '+';

protected $zvalOperator = 'mul_function';
protected string $zvalOperator = 'mul_function';
}
6 changes: 3 additions & 3 deletions Library/Operators/Arithmetical/SubOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
class SubOperator extends ArithmeticalBaseOperator
{
protected $operator = '-';
protected string $operator = '-';

protected $bitOperator = '&';
protected string $bitOperator = '&';

protected $zvalOperator = 'zephir_sub_function';
protected string $zvalOperator = 'zephir_sub_function';
}
26 changes: 14 additions & 12 deletions Library/Operators/BaseOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@
use Zephir\CompilationContext;
use Zephir\Variable;

/**
* TODO: Make it abstract
*/
class BaseOperator
{
protected $operator;
protected string $operator;

protected $expecting = true;
protected bool $expecting = true;

protected $readOnly = false;
protected bool $readOnly = false;

protected $literalOnly = true;
protected bool $literalOnly = true;

/** @var Variable|null */
protected $expectingVariable;
protected ?Variable $expectingVariable = null;

/**
* Sets if the variable must be resolved into a direct variable symbol
* create a temporary value or ignore the return value.
*
* @param bool $expecting
* @param Variable $expectingVariable
* @param bool $expecting
* @param Variable|null $expectingVariable
*/
public function setExpectReturn($expecting, Variable $expectingVariable = null)
public function setExpectReturn(bool $expecting, Variable $expectingVariable = null)
{
$this->expecting = $expecting;
$this->expectingVariable = $expectingVariable;
Expand Down Expand Up @@ -166,7 +168,7 @@ public function getExpectedComplexLiteral(CompilationContext $compilationContext
*
* @return bool
*/
public function isExpecting()
public function isExpecting(): bool
{
return $this->expecting;
}
Expand All @@ -176,7 +178,7 @@ public function isExpecting()
*
* @param bool $readOnly
*/
public function setReadOnly($readOnly)
public function setReadOnly(bool $readOnly): void
{
$this->readOnly = $readOnly;
}
Expand All @@ -186,7 +188,7 @@ public function setReadOnly($readOnly)
*
* @return bool
*/
public function isReadOnly()
public function isReadOnly(): bool
{
return $this->readOnly;
}
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Bitwise/BitwiseAndOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class BitwiseAndOperator extends BitwiseBaseOperator
{
protected $operator = '&';
protected string $operator = '&';

protected $bitOperator = '&';
protected string $bitOperator = '&';

protected $zvalOperator = 'zephir_bitwise_and_function';
protected string $zvalOperator = 'zephir_bitwise_and_function';
}
2 changes: 1 addition & 1 deletion Library/Operators/Bitwise/BitwiseBaseOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class BitwiseBaseOperator extends BaseOperator
{
protected $literalOnly = true;
protected bool $literalOnly = true;

/**
* This tries to perform arithmetical operations
Expand Down
6 changes: 3 additions & 3 deletions Library/Operators/Bitwise/BitwiseOrOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class BitwiseOrOperator extends BitwiseBaseOperator
{
protected $operator = '|';
protected string $operator = '|';

protected $bitOperator = '|';
protected string $bitOperator = '|';

protected $zvalOperator = 'zephir_bitwise_or_function';
protected string $zvalOperator = 'zephir_bitwise_or_function';
}
6 changes: 3 additions & 3 deletions Library/Operators/Bitwise/BitwiseXorOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class BitwiseXorOperator extends BitwiseBaseOperator
{
protected $operator = '^';
protected string $operator = '^';

protected $bitOperator = '^';
protected string $bitOperator = '^';

protected $zvalOperator = 'zephir_bitwise_xor_function';
protected string $zvalOperator = 'zephir_bitwise_xor_function';
}
6 changes: 3 additions & 3 deletions Library/Operators/Bitwise/ShiftLeftOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class ShiftLeftOperator extends BitwiseBaseOperator
{
protected $operator = '<<';
protected string $operator = '<<';

protected $bitOperator = '<<';
protected string $bitOperator = '<<';

protected $zvalOperator = 'zephir_shift_left_function';
protected string $zvalOperator = 'zephir_shift_left_function';
}
6 changes: 3 additions & 3 deletions Library/Operators/Bitwise/ShiftRightOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

class ShiftRightOperator extends BitwiseBaseOperator
{
protected $operator = '>>';
protected string $operator = '>>';

protected $bitOperator = '>>';
protected string $bitOperator = '>>';

protected $zvalOperator = 'zephir_shift_right_function';
protected string $zvalOperator = 'zephir_shift_right_function';
}
8 changes: 5 additions & 3 deletions Library/Operators/Comparison/ComparisonBaseOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Operators\Comparison;

use Zephir\CompilationContext;
Expand All @@ -24,9 +26,9 @@
*/
class ComparisonBaseOperator extends BaseOperator
{
protected $literalOnly = true;
protected bool $literalOnly = true;

protected $commutative = false;
protected bool $commutative = false;

/**
* @param $expr
Expand Down Expand Up @@ -551,7 +553,7 @@ public function compile($expression, CompilationContext $compilationContext)
case 'null':
$compilationContext->headersManager->add('kernel/operators');

return new CompiledExpression('bool', $this->zvalStringOperator.'('.$variableCode.', "")', $expression['left']);
return new CompiledExpression('bool', $this->zvalNullOperator.'('.$variableCode.')', $expression['left']);

case 'string':
$compilationContext->headersManager->add('kernel/operators');
Expand Down
22 changes: 12 additions & 10 deletions Library/Operators/Comparison/EqualsOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@

class EqualsOperator extends ComparisonBaseOperator
{
protected $commutative = true;
protected bool $commutative = true;

protected $operator = '==';
protected string $operator = '==';

protected $bitOperator = '==';
protected string $bitOperator = '==';

protected $zvalOperator = 'ZEPHIR_IS_EQUAL';
protected string $zvalOperator = 'ZEPHIR_IS_EQUAL';

protected $zvalLongOperator = 'ZEPHIR_IS_LONG';
protected string $zvalLongOperator = 'ZEPHIR_IS_LONG';

protected $zvalLongNegOperator = 'ZEPHIR_IS_LONG';
protected string $zvalLongNegOperator = 'ZEPHIR_IS_LONG';

protected $zvalStringOperator = 'ZEPHIR_IS_STRING';
protected string $zvalStringOperator = 'ZEPHIR_IS_STRING';

protected $zvalBoolOperator = 'ZEPHIR_IS_BOOL_VALUE';
protected string $zvalBoolOperator = 'ZEPHIR_IS_BOOL_VALUE';

protected $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE';
protected string $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE';

protected $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE';
protected string $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE';

protected string $zvalNullOperator = 'ZEPHIR_IS_NULL';
}
14 changes: 7 additions & 7 deletions Library/Operators/Comparison/GreaterEqualOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

class GreaterEqualOperator extends ComparisonBaseOperator
{
protected $operator = '>=';
protected string $operator = '>=';

protected $bitOperator = '>=';
protected string $bitOperator = '>=';

protected $zvalOperator = 'ZEPHIR_GE';
protected string $zvalOperator = 'ZEPHIR_GE';

protected $zvalLongOperator = 'ZEPHIR_GE_LONG';
protected string $zvalLongOperator = 'ZEPHIR_GE_LONG';

protected $zvalLongNegOperator = 'ZEPHIR_LE_LONG';
protected string $zvalLongNegOperator = 'ZEPHIR_LE_LONG';

protected $zvalDoubleOperator = '!ZEPHIR_LT_DOUBLE';
protected string $zvalDoubleOperator = '!ZEPHIR_LT_DOUBLE';

protected $zvalDoubleNegOperator = '!ZEPHIR_GT_DOUBLE';
protected string $zvalDoubleNegOperator = '!ZEPHIR_GT_DOUBLE';
}
14 changes: 7 additions & 7 deletions Library/Operators/Comparison/GreaterOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

class GreaterOperator extends ComparisonBaseOperator
{
protected $operator = '>';
protected string $operator = '>';

protected $bitOperator = '>';
protected string $bitOperator = '>';

protected $zvalOperator = 'ZEPHIR_GT';
protected string $zvalOperator = 'ZEPHIR_GT';

protected $zvalLongOperator = 'ZEPHIR_GT_LONG';
protected string $zvalLongOperator = 'ZEPHIR_GT_LONG';

protected $zvalLongNegOperator = 'ZEPHIR_LT_LONG';
protected string $zvalLongNegOperator = 'ZEPHIR_LT_LONG';

protected $zvalDoubleOperator = 'ZEPHIR_GT_DOUBLE';
protected string $zvalDoubleOperator = 'ZEPHIR_GT_DOUBLE';

protected $zvalDoubleNegOperator = 'ZEPHIR_LT_DOUBLE';
protected string $zvalDoubleNegOperator = 'ZEPHIR_LT_DOUBLE';
}
22 changes: 12 additions & 10 deletions Library/Operators/Comparison/IdenticalOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@

class IdenticalOperator extends ComparisonBaseOperator
{
protected $commutative = true;
protected bool $commutative = true;

protected $operator = '==';
protected string $operator = '==';

protected $bitOperator = '==';
protected string $bitOperator = '==';

protected $zvalOperator = 'ZEPHIR_IS_IDENTICAL';
protected string $zvalOperator = 'ZEPHIR_IS_IDENTICAL';

protected $zvalLongOperator = 'ZEPHIR_IS_LONG_IDENTICAL';
protected string $zvalLongOperator = 'ZEPHIR_IS_LONG_IDENTICAL';

protected $zvalLongNegOperator = 'ZEPHIR_IS_LONG_IDENTICAL';
protected string $zvalLongNegOperator = 'ZEPHIR_IS_LONG_IDENTICAL';

protected $zvalStringOperator = 'ZEPHIR_IS_STRING_IDENTICAL';
protected string $zvalStringOperator = 'ZEPHIR_IS_STRING_IDENTICAL';

protected $zvalBoolOperator = 'ZEPHIR_IS_BOOL_IDENTICAL';
protected string $zvalBoolOperator = 'ZEPHIR_IS_BOOL_IDENTICAL';

protected $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE_IDENTICAL';
protected string $zvalBoolTrueOperator = 'ZEPHIR_IS_TRUE_IDENTICAL';

protected $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE_IDENTICAL';
protected string $zvalBoolFalseOperator = 'ZEPHIR_IS_FALSE_IDENTICAL';

protected string $zvalNullOperator = 'ZEPHIR_IS_NULL';
}
Loading

0 comments on commit 006b504

Please sign in to comment.