Permalink
Browse files

Fix as-expression irgen for vec/dict

Summary: We didn't bail early for as-expressions when checking for vec/dict in irgen, leading us to emit an is-expression instead of an as-expression.

Reviewed By: oulgen

Differential Revision: D8708371

fbshipit-source-id: e7212873d91f09f7b3783a78a1510dd2a72b42b2
  • Loading branch information...
kmeht authored and hhvm-bot committed Jun 30, 2018
1 parent 2d82103 commit 3fdf00e65cf129d39df4e2bcf32891eac3206b15
@@ -847,6 +847,7 @@ bool emitIsAsTypeStructWithoutResolvingIfPossible(
return unionOf(TArr, TVec, TDict, TKeyset);
case TypeStructure::Kind::T_dict:
case TypeStructure::Kind::T_vec: {
if (asExpr) return false;
auto const c = popC(env);
auto const res = kind == TypeStructure::Kind::T_dict
? isDictImpl(env, c)
@@ -0,0 +1,20 @@
<?hh
function f(mixed $x): void {
try {
var_dump($x as dict);
} catch (TypeAssertionException $_) {
echo "not dict: ".gettype($x)."\n";
}
}
f(1);
f(false);
f(1.5);
f('foo');
f(STDIN);
f(new stdClass());
f(vec[]);
f(dict[]);
f(keyset[]);
f(null);
@@ -0,0 +1,11 @@
not dict: integer
not dict: boolean
not dict: double
not dict: string
not dict: resource
not dict: object
not dict: vec
dict(0) {
}
not dict: keyset
not dict: NULL
@@ -0,0 +1,20 @@
<?hh
function f(mixed $x): void {
try {
var_dump($x as vec);
} catch (TypeAssertionException $_) {
echo "not vec: ".gettype($x)."\n";
}
}
f(1);
f(false);
f(1.5);
f('foo');
f(STDIN);
f(new stdClass());
f(vec[]);
f(dict[]);
f(keyset[]);
f(null);
@@ -0,0 +1,11 @@
not vec: integer
not vec: boolean
not vec: double
not vec: string
not vec: resource
not vec: object
vec(0) {
}
not vec: dict
not vec: keyset
not vec: NULL

0 comments on commit 3fdf00e

Please sign in to comment.