From d33bb88a15f4923e7e0ede1260d9b68fad21832c Mon Sep 17 00:00:00 2001 From: Josh Watzman Date: Wed, 21 May 2014 11:25:10 -0700 Subject: [PATCH] Using dynamic classes in strict is not a parse error Summary: We need to move anything like this after parsing, so that you can `UNSAFE` it. @KendallHopkins ran into this specifically. Reviewed By: @pikatchu Differential Revision: D1341785 --- hphp/hack/src/naming/naming.ml | 2 ++ hphp/hack/src/parsing/parser_hack.ml | 3 -- hphp/hack/test/typecheck/method_dispatch_37.php | 41 ++++++++++++++++++++++ .../hack/test/typecheck/method_dispatch_37.php.exp | 1 + 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 hphp/hack/test/typecheck/method_dispatch_37.php create mode 100644 hphp/hack/test/typecheck/method_dispatch_37.php.exp diff --git a/hphp/hack/src/naming/naming.ml b/hphp/hack/src/naming/naming.ml index a2cdccf3333..28042483b00 100644 --- a/hphp/hack/src/naming/naming.ml +++ b/hphp/hack/src/naming/naming.ml @@ -1683,6 +1683,8 @@ and expr_lambda env f = and make_class_id env cid = no_typedef env cid; match snd cid with + | x when x.[0] = '$' && (fst env).in_mode = Ast.Mstrict -> + error (fst cid) "Don't use dynamic classes" | "parent" -> N.CIparent | "self" -> N.CIself | "static" -> N.CIstatic diff --git a/hphp/hack/src/parsing/parser_hack.ml b/hphp/hack/src/parsing/parser_hack.ml index 8e2e34fde6a..185c892ed88 100644 --- a/hphp/hack/src/parsing/parser_hack.ml +++ b/hphp/hack/src/parsing/parser_hack.ml @@ -2402,9 +2402,6 @@ and expr_colcol env e1 = | (_, Id cname) -> (* XYZ::class is OK ... *) expr_colcol_remain ~allow_class:true env e1 cname - | pos, Lvar cname when env.mode = Ast.Mstrict -> - error_at env pos "Don't use dynamic classes"; - e1 | pos, Lvar cname -> (* ... but get_class($x) should be used instead of $x::class *) expr_colcol_remain ~allow_class:false env e1 cname diff --git a/hphp/hack/test/typecheck/method_dispatch_37.php b/hphp/hack/test/typecheck/method_dispatch_37.php new file mode 100644 index 00000000000..cbfc6eb08e3 --- /dev/null +++ b/hphp/hack/test/typecheck/method_dispatch_37.php @@ -0,0 +1,41 @@ +