Browse Source

[parser] fix type path magic

closes #6499
Simon Krajewski 7 years ago
parent
commit
0df331eb55
3 changed files with 23 additions and 2 deletions
  1. 1 1
      src/syntax/grammar.mly
  2. 1 1
      src/typing/typeload.ml
  3. 21 0
      tests/unit/src/unit/issues/Issue6499.hx

+ 1 - 1
src/syntax/grammar.mly

@@ -450,7 +450,7 @@ and parse_class_flags = parser
 
 and parse_complex_type_at p = parser
 	| [< t = parse_complex_type >] -> t
-	| [< s >] -> if would_skip_display_position p s then CTPath { tpackage = []; tname = ""; tparams = []; tsub = None },p else serror()
+	| [< s >] -> if would_skip_display_position p s then CTPath magic_type_path,p else serror()
 
 and parse_type_hint = parser
 	| [< '(DblDot,p1); s >] ->

+ 1 - 1
src/typing/typeload.ml

@@ -105,9 +105,9 @@ with Error((Module_not_found _ | Type_not_found _),p2) when p = p2 ->
 *)
 let load_type_def ctx p t =
 	let no_pack = t.tpackage = [] in
+	if t == Parser.magic_type_path then raise_fields (DisplayToplevel.collect ctx None NoValue) CRTypeHint None;
 	(* The type name is the module name or the module sub-type name *)
 	let tname = (match t.tsub with None -> t.tname | Some n -> n) in
-	if tname = "" then raise_fields (DisplayToplevel.collect ctx None NoValue) CRTypeHint None;
 	try
 		(* If there's a sub-type, there's no reason to look in our module or its imports *)
 		if t.tsub <> None then raise Not_found;

+ 21 - 0
tests/unit/src/unit/issues/Issue6499.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+class Issue6499 extends unit.Test {
+	function test() {
+		#if !macro
+		t(Macro.test());
+		#end
+	}
+}
+
+private class Macro {
+	macro static public function test() {
+		var b = try {
+			haxe.macro.Context.getType('any.string.which.ends.with.dot.');
+			false;
+		} catch(e:Dynamic) {
+			true;
+		}
+		return macro $v{b};
+	}
+}