Browse Source

[typer] fix path matching of top-level types

closes #10591
Simon Krajewski 3 years ago
parent
commit
ead88701f5

+ 5 - 5
src/core/ast.ml

@@ -1016,22 +1016,22 @@ let expr_of_type_path (sl,s) p =
 		EField(e,s),p
 		EField(e,s),p
 
 
 let match_path recursive sl sl_pattern =
 let match_path recursive sl sl_pattern =
-	let rec loop sl1 sl2 = match sl1,sl2 with
+	let rec loop top sl1 sl2 = match sl1,sl2 with
 		| [],[] ->
 		| [],[] ->
 			true
 			true
 		(* always recurse into types of package paths *)
 		(* always recurse into types of package paths *)
 		| (s1 :: s11 :: _),[s2] when is_lower_ident s2 && not (is_lower_ident s11)->
 		| (s1 :: s11 :: _),[s2] when is_lower_ident s2 && not (is_lower_ident s11)->
 			s1 = s2
 			s1 = s2
-		| [_],[""] ->
+		| [_],[] when top ->
 			true
 			true
-		| _,([] | [""]) ->
+		| _,[] ->
 			recursive
 			recursive
 		| [],_ ->
 		| [],_ ->
 			false
 			false
 		| (s1 :: sl1),(s2 :: sl2) ->
 		| (s1 :: sl1),(s2 :: sl2) ->
-			s1 = s2 && loop sl1 sl2
+			s1 = s2 && loop false sl1 sl2
 	in
 	in
-	loop sl sl_pattern
+	loop true sl sl_pattern
 
 
 let full_dot_path2 mpath tpath =
 let full_dot_path2 mpath tpath =
 	if mpath = tpath then
 	if mpath = tpath then

+ 27 - 0
tests/misc/projects/Issue10591/Main.hx

@@ -0,0 +1,27 @@
+import haxe.rtti.Meta;
+using Lambda;
+
+
+class MainSub {}
+
+class Main {
+	static function main() {
+		function hf(t, s) {
+			Sys.stderr().writeString('$s: ${Reflect.hasField(t, s)}\n');
+		}
+
+		final numMetas = 6;
+
+		var check = [
+			{ name: "Main", meta: Meta.getType(Main) },
+			{ name: "MainSub", meta: Meta.getType(MainSub) }
+		];
+
+		for (item in check) {
+			Sys.stderr().writeString(item.name + "\n");
+			for (i in 0...numMetas) {
+				hf(item.meta, 'meta$i');
+			}
+		}
+	}
+}

+ 8 - 0
tests/misc/projects/Issue10591/compile.hxml

@@ -0,0 +1,8 @@
+--main Main
+--interp
+--macro addGlobalMetadata("", "@meta0", false)
+--macro addGlobalMetadata("", "@meta1", true)
+--macro addGlobalMetadata("Main", "@meta2", false)
+--macro addGlobalMetadata("Main", "@meta3", true)
+--macro addGlobalMetadata("Main.MainSub", "@meta4", false)
+--macro addGlobalMetadata("Main.MainSub", "@meta5", true)

+ 14 - 0
tests/misc/projects/Issue10591/compile.hxml.stderr

@@ -0,0 +1,14 @@
+Main
+meta0: true
+meta1: true
+meta2: true
+meta3: true
+meta4: false
+meta5: false
+MainSub
+meta0: false
+meta1: true
+meta2: false
+meta3: true
+meta4: true
+meta5: true