Fix type assertions for array-like interfaces

Without this we could infer that an array was an object,
skip the guards, and then die horribly.
Esse commit está contido em:
mwilliams
2013-07-02 11:09:58 -07:00
commit de Sara Golemon
commit 52b914a4c9
3 arquivos alterados com 23 adições e 0 exclusões
+6
Ver Arquivo
@@ -64,6 +64,8 @@
#include "hphp/compiler/analysis/live_dict.h"
#include "hphp/compiler/analysis/ref_dict.h"
#include "hphp/runtime/base/builtin_functions.h"
#include "hphp/util/parser/hphp.tab.hpp"
#include "hphp/util/parser/location.h"
#include "hphp/util/util.h"
@@ -2638,6 +2640,10 @@ private:
if (sv && se) {
const string &s = se->getLiteralString();
if (s.empty()) return ExpressionPtr();
if (interface_supports_array(s)) {
// This could be an array, so don't assert anything
return ExpressionPtr();
}
TypePtr o(Type::CreateObjectType(Util::toLower(s)));
// don't do specific type assertions for unknown classes
@@ -0,0 +1,13 @@
<?hh
function foo(KeyedTraversable<String> $foo, $f) {
var_dump($foo);
}
function test($a) {
if ($a instanceof KeyedTraversable) {
foo($a, false);
}
}
test(array(1));
@@ -0,0 +1,4 @@
array(1) {
[0]=>
int(1)
}