Permalink
Browse files

Add tests for various already implemented features

Summary: This diff just adds tests for various specifications that are already implemented in the base revision.

Reviewed By: dlreeves

Differential Revision: D6764209

fbshipit-source-id: 0d325cdc7784c408332afa459ee940cb6407bc9e
  • Loading branch information...
jamesjwu authored and hhvm-bot committed Feb 16, 2018
1 parent 74f69be commit d08bc038bdc355c48dd99c281cefba6565cb3640
@@ -0,0 +1,8 @@
<?hh // strict
function testAssign(dynamic $x, dynamic $y): void {
$x += 5; // $x is now a num
hh_show($x);
$y .= "string"; // $y is now a string
hh_show($y);
}
@@ -0,0 +1,5 @@
File "assignment.php", line 5, characters 3-13:
num
File "assignment.php", line 7, characters 3-13:
string
No errors
@@ -0,0 +1,17 @@
<?hh // strict
function testBools(dynamic $x): void {
$y = $x && true; // $y : bool
hh_show($y);
$y = $x || false; // $y : bool
hh_show($y);
$y = !$x; // $y : bool
hh_show($y);
$y = $x === 5; // $y : bool
hh_show($y);
$y = $x == 5; // $y : bool
hh_show($y);
if ($x) // valid, no sketchy null check warning
{
}
}
@@ -0,0 +1,11 @@
File "booleans.php", line 5, characters 3-13:
bool
File "booleans.php", line 7, characters 3-13:
bool
File "booleans.php", line 9, characters 3-13:
bool
File "booleans.php", line 11, characters 3-13:
bool
File "booleans.php", line 13, characters 3-13:
bool
No errors
@@ -0,0 +1,8 @@
<?hh // strict
function testClassName(classname<dynamic> $x): void {
$y = $x::staticMeth(); // $y : dynamic
hh_show($y);
$y = $x::staticProp; // $y : dynamic
hh_show($y);
}
@@ -0,0 +1,5 @@
File "classname.php", line 5, characters 3-13:
dynamic
File "classname.php", line 7, characters 3-13:
dynamic
No errors
@@ -0,0 +1,17 @@
<?hh // strict
function testCollections(dynamic $x): void {
$y = vec[];
$y[] = 5; // $y : vec<int>
hh_show($y);
$y[] = $x; // $y : vec<(int | dynamic)>
hh_show($y);
$y = Vector { $x }; // $y : Vector<dynamic>
hh_show($y);
$y = Map { 5 => $x }; // $y : Map<int, dynamic>
hh_show($y);
}
function testCollections2(vec<int> $a, dynamic $x): void {
$a[] = $x; // error, $a is of type vec<int>, incompatible with dynamic
}
@@ -0,0 +1,14 @@
File "collections.php", line 6, characters 3-13:
vec<^(int)>
File "collections.php", line 8, characters 3-13:
vec<^(int | dynamic)>
File "collections.php", line 10, characters 3-13:
Vector<^(dynamic)>
File "collections.php", line 12, characters 3-13:
Map<^(int), ^(dynamic)>
File "collections.php", line 16, characters 3-11:
Invalid assignment (Typing[4110])
File "collections.php", line 15, characters 31-33:
This is an int
File "collections.php", line 15, characters 40-46:
It is incompatible with a dynamic value
@@ -0,0 +1,9 @@
<?hh // strict
function testObjGet(dynamic $x): void {
$y = $x::staticProp; // $y : dynamic
hh_show($y);
$y = $x->property; // $y : dynamic
hh_show($y);
$x->property = 7;
}
@@ -0,0 +1,5 @@
File "obj_get.php", line 5, characters 3-13:
dynamic
File "obj_get.php", line 7, characters 3-13:
dynamic
No errors
@@ -0,0 +1,8 @@
<?hh // strict
function testString(dynamic $x): void {
$y = $x."hello"; // $y : string
hh_show($y);
$y = $x.$x; // $y : string
hh_show($y);
}
@@ -0,0 +1,5 @@
File "string_concat.php", line 5, characters 3-13:
string
File "string_concat.php", line 7, characters 3-13:
string
No errors

0 comments on commit d08bc03

Please sign in to comment.