Skip to content

Commit

Permalink
Add tests for various already implemented features
Browse files Browse the repository at this point in the history
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 d08bc03
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hphp/hack/test/typecheck/dynamic/assignment.php
@@ -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);
}
5 changes: 5 additions & 0 deletions hphp/hack/test/typecheck/dynamic/assignment.php.exp
@@ -0,0 +1,5 @@
File "assignment.php", line 5, characters 3-13:
num
File "assignment.php", line 7, characters 3-13:
string
No errors
17 changes: 17 additions & 0 deletions hphp/hack/test/typecheck/dynamic/booleans.php
@@ -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
{
}
}
11 changes: 11 additions & 0 deletions hphp/hack/test/typecheck/dynamic/booleans.php.exp
@@ -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
8 changes: 8 additions & 0 deletions hphp/hack/test/typecheck/dynamic/classname.php
@@ -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);
}
5 changes: 5 additions & 0 deletions hphp/hack/test/typecheck/dynamic/classname.php.exp
@@ -0,0 +1,5 @@
File "classname.php", line 5, characters 3-13:
dynamic
File "classname.php", line 7, characters 3-13:
dynamic
No errors
17 changes: 17 additions & 0 deletions hphp/hack/test/typecheck/dynamic/collections.php
@@ -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
}
14 changes: 14 additions & 0 deletions hphp/hack/test/typecheck/dynamic/collections.php.exp
@@ -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
9 changes: 9 additions & 0 deletions hphp/hack/test/typecheck/dynamic/obj_get.php
@@ -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;
}
5 changes: 5 additions & 0 deletions hphp/hack/test/typecheck/dynamic/obj_get.php.exp
@@ -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
8 changes: 8 additions & 0 deletions hphp/hack/test/typecheck/dynamic/string_concat.php
@@ -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);
}
5 changes: 5 additions & 0 deletions hphp/hack/test/typecheck/dynamic/string_concat.php.exp
@@ -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.