Skip to content

Commit

Permalink
test on 4.128 (#79)
Browse files Browse the repository at this point in the history
* test on 4.128

* Copy over changes from Slack source-code (#80)

* fix trailing comma

* fix tests and fix behavior for GREATEST()

Co-authored-by: Matthew Brown <github@muglug.com>
  • Loading branch information
ssandler and muglug committed Feb 2, 2022
1 parent 6756034 commit be51f53
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
os: [ ubuntu ]
hhvm:
- '4.121'
- '4.128'
runs-on: ${{matrix.os}}-latest
steps:
- uses: actions/checkout@v2
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"MIT"
],
"require": {
"hhvm/hsl": "^4.0.1",
"hhvm/hsl-experimental": "^4.50",
"facebook/hack-codegen": "^4.1.0",
"hhvm/hhast": "v4.135.1",
"hhvm/hsl-experimental": "=4.108.0",
"facebook/hack-codegen": "^4.3.12",
"facebook/hh-clilib": "^2.0.0",
"hhvm/hhvm-autoload": "^2.0.4|^3"
"hhvm/hhvm-autoload": "^2.0.13|^3.1.4"
},
"require-dev": {
"hhvm/hhast": "^4.80",
"facebook/fbexpect": "^2.2.0",
"hhvm/hacktest": "^1.3|^2.0"
"facebook/fbexpect": "^2.8.0",
"hhvm/hacktest": "=2.2.3"
}
}
16 changes: 8 additions & 8 deletions src/Expressions/BinaryOperatorExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function evaluateRowComparison(

// in an expression like (1, 2, 3) > (1, 2, 2) we don't need EVERY element on the left to be greater than the right
// some can be equal. so if we get to one that isn't the last and they're equal, it's safe to keep going
if ($le == $re && $index !== $last_index) {
if (\HH\Lib\Legacy_FIXME\eq($le, $re) && $index !== $last_index) {
continue;
}

Expand All @@ -81,7 +81,7 @@ private function evaluateRowComparison(
return ($le >= $re);
case Operator::LESS_THAN:
/* HH_IGNORE_ERROR[4240] assume they have the same types */
return ($le < $re);
return \HH\Lib\Legacy_FIXME\lt($le, $re);
case Operator::LESS_THAN_EQUALS:
/* HH_IGNORE_ERROR[4240] assume they have the same types */
return ($le <= $re);
Expand Down Expand Up @@ -154,39 +154,39 @@ public function evaluateImpl(row $row, AsyncMysqlConnection $conn): mixed {
case Operator::EQUALS:
// maybe do some stuff with data types here
// comparing strings: gotta think about collation and case sensitivity!
return (bool)(($l_value == $r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(\HH\Lib\Legacy_FIXME\eq($l_value, $r_value) ? 1 : 0 ^ $this->negatedInt);
case Operator::LESS_THAN_GREATER_THAN:
case Operator::BANG_EQUALS:
if ($as_string) {
return (bool)(((string)$l_value != (string)$r_value) ? 1 : 0 ^ $this->negatedInt);
} else {
return (bool)(((int)$l_value != (int)$r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(((float)$l_value != (float)$r_value) ? 1 : 0 ^ $this->negatedInt);
}
case Operator::GREATER_THAN:
if ($as_string) {
return (bool)((((Str\compare((string)$l_value, (string)$r_value)) > 0) ? 1 : 0) ^ $this->negatedInt);
} else {
return (bool)(((int)$l_value > (int)$r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(((float)$l_value > (float)$r_value) ? 1 : 0 ^ $this->negatedInt);
}
case Operator::GREATER_THAN_EQUALS:
if ($as_string) {
$comparison = Str\compare((string)$l_value, (string)$r_value);
return (bool)((($comparison > 0 || $comparison === 0) ? 1 : 0) ^ $this->negatedInt);
} else {
return (bool)(((int)$l_value >= (int)$r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(((float)$l_value >= (float)$r_value) ? 1 : 0 ^ $this->negatedInt);
}
case Operator::LESS_THAN:
if ($as_string) {
return (bool)((((Str\compare((string)$l_value, (string)$r_value)) < 0) ? 1 : 0) ^ $this->negatedInt);
} else {
return (bool)(((int)$l_value < (int)$r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(((float)$l_value < (float)$r_value) ? 1 : 0 ^ $this->negatedInt);
}
case Operator::LESS_THAN_EQUALS:
if ($as_string) {
$comparison = Str\compare((string)$l_value, (string)$r_value);
return (bool)((($comparison < 0 || $comparison === 0) ? 1 : 0) ^ $this->negatedInt);
} else {
return (bool)(((int)$l_value <= (int)$r_value) ? 1 : 0 ^ $this->negatedInt);
return (bool)(((float)$l_value <= (float)$r_value) ? 1 : 0 ^ $this->negatedInt);
}
case Operator::ASTERISK:
case Operator::PERCENT:
Expand Down
4 changes: 4 additions & 0 deletions src/Expressions/FunctionExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ private function sqlGreatest(row $row, AsyncMysqlConnection $conn): mixed {
$values = vec[];
foreach ($this->args as $arg) {
$val = $arg->evaluate($row, $conn);
// MySQL always returns null if ANY argument to this function is null
if ($val is null) {
return null;
}
$values[] = $val;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/SQLFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ final class SQLFunctionTest extends HackTest {
$results = await $conn->query(
'SELECT GREATEST(1, 3, 2) as first, GREATEST(NULL, 2) as second, GREATEST(NULL, NULL, NULL) as third',
);
// GREATEST returns null if any args are null
expect($results->rows())->toBeSame(vec[
dict['first' => 3, 'second' => 2, 'third' => null],
dict['first' => 3, 'second' => null, 'third' => null],
]);
}

Expand Down

0 comments on commit be51f53

Please sign in to comment.