Forráskód Böngészése

support `@:const T` instead of Const for type parameters

Simon Krajewski 10 éve
szülő
commit
9e7eb804a6
2 módosított fájl, 14 hozzáadás és 4 törlés
  1. 1 1
      tests/unit/src/unit/issues/Issue2958.hx
  2. 13 3
      typeload.ml

+ 1 - 1
tests/unit/src/unit/issues/Issue2958.hx

@@ -1,6 +1,6 @@
 package unit.issues;
 
-private typedef Asset<Const> = String;
+private typedef Asset<@:const T> = String;
 
 class Issue2958 extends Test {
     function test() {

+ 13 - 3
typeload.ml

@@ -413,13 +413,23 @@ let rec load_instance ctx t p allow_no_params =
 			) t.tparams in
 			let rec loop tl1 tl2 is_rest = match tl1,tl2 with
 				| t :: tl1,(name,t2) :: tl2 ->
-					let isconst = (match t with TInst ({ cl_kind = KExpr _ },_) -> true | _ -> false) in
-					if isconst <> (name = "Const") && t != t_dynamic && name <> "Rest" then error (if isconst then "Constant value unexpected here" else "Constant value excepted as type parameter") p;
+					let check_const c =
+						let is_expression = (match t with TInst ({ cl_kind = KExpr _ },_) -> true | _ -> false) in
+						let expects_expression = name = "Const" || Meta.has (Meta.Custom ":const") c.cl_meta in
+						let accepts_expression = name = "Rest" in
+						if is_expression then begin
+							if not expects_expression && not accepts_expression then
+								error "Constant value unexpected here" p
+						end else if expects_expression then
+							error "Constant value excepted as type parameter" p
+					in
 					let is_rest = is_rest || name = "Rest" && is_generic_build in
 					let t = match follow t2 with
-						| TInst ({ cl_kind = KTypeParameter [] }, []) when not is_generic ->
+						| TInst ({ cl_kind = KTypeParameter [] } as c, []) when not is_generic ->
+							check_const c;
 							t
 						| TInst (c,[]) ->
+							check_const c;
 							let r = exc_protect ctx (fun r ->
 								r := (fun() -> t);
 								delay ctx PCheckConstraint (fun() -> check_param_constraints ctx types t tparams c p);