Przeglądaj źródła

do not allow import/using after type declaration

Simon Krajewski 13 lat temu
rodzic
commit
fc956cb45f
2 zmienionych plików z 14 dodań i 4 usunięć
  1. 4 4
      tests/unit/MyClass.hx
  2. 10 0
      typeload.ml

+ 4 - 4
tests/unit/MyClass.hx

@@ -1,5 +1,9 @@
 package unit;
 
+using MyClass.UsingBase;
+using MyClass.UsingChild1;
+using MyClass.UsingChild2;
+
 class MyClass {
 
 	#if as3 public #end var val : Int;
@@ -163,10 +167,6 @@ class UsingBase {
 	static public function pupFunc(s:String) return s.toUpperCase()
 }
 
-using MyClass.UsingBase;
-using MyClass.UsingChild1;
-using MyClass.UsingChild2;
-
 class UsingChild1 extends UsingBase {
 	static public function test() {
 		return "foo".pupFunc() + "foo".privFunc() + "FOO".siblingFunc();

+ 10 - 0
typeload.ml

@@ -36,11 +36,19 @@ let make_module ctx mpath file tdecls loadp =
 		m_types = [];
 		m_extra = module_extra (Common.unique_full_path file) (Common.get_signature ctx.com) (file_time file) (if ctx.in_macro then MMacro else MCode);
 	} in
+	let pt = ref None in
 	List.iter (fun decl ->
 		let p = snd decl in
 		match fst decl with
+		| EImport _ | EUsing _ when Common.defined ctx.com Define.Haxe3 ->
+			(match !pt with
+			| None -> ()
+			| Some pt ->
+				display_error ctx "import and using may not appear after a type declaration" p;
+				error "Previous type declaration found here" pt)
 		| EImport _ | EUsing _ -> ()
 		| EClass d ->
+			pt := Some p;
 			let priv = List.mem HPrivate d.d_flags in
 			let path = make_path d.d_name priv in
 			let c = mk_class m path p in
@@ -50,6 +58,7 @@ let make_module ctx mpath file tdecls loadp =
 			c.cl_meta <- d.d_meta;
 			decls := (TClassDecl c, decl) :: !decls
 		| EEnum d ->
+			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
 			let path = make_path d.d_name priv in
 			let e = {
@@ -66,6 +75,7 @@ let make_module ctx mpath file tdecls loadp =
 			} in
 			decls := (TEnumDecl e, decl) :: !decls
 		| ETypedef d ->
+			pt := Some p;
 			let priv = List.mem EPrivate d.d_flags in
 			let path = make_path d.d_name priv in
 			let t = {