Browse Source

add :hack to type parameters to allow basic type constraints on all platforms

Simon Krajewski 13 years ago
parent
commit
0a3f4b53fd
3 changed files with 5 additions and 0 deletions
  1. 1 0
      tests/unit/MyClass.hx
  2. 3 0
      tests/unit/TestType.hx
  3. 1 0
      typeload.ml

+ 1 - 0
tests/unit/MyClass.hx

@@ -133,4 +133,5 @@ class ParamConstraintsClass {
 	public function memberSingle< A:Base > (a:A):A { return a; }
 	public function memberMultiple < A:(Base, I1) > (a:A):A { return a; }
 	public function memberComplex < A:I1, B:List<A> > (a:A, b:B) { return b; }
+	public function memberBasic < A:String, B:Array<A> > (a:A, b:B) { return b[0]; }
 }

+ 3 - 0
tests/unit/TestType.hx

@@ -427,5 +427,8 @@ class TestType extends Test {
 		eq(pcc.memberComplex(ci1, l), l);
 		eq(pcc.memberComplex(ci1, lmono), lmono);
 		//typeError(pcc.memberComplex(ci1, [ci1]));
+		
+		eq(pcc.memberBasic("foo", ["bar"]), "bar");
+		//eq(pcc.memberBasic("foo", ["bar"]), "foobar");
 	}
 }

+ 1 - 0
typeload.ml

@@ -580,6 +580,7 @@ let set_heritance ctx c herits p =
 let type_type_params ctx path get_params p (n,flags) =
 	let c = mk_class ctx.current (fst path @ [snd path],n) p in
 	c.cl_kind <- KTypeParameter;
+	c.cl_meta <- (":hack",[],p) :: c.cl_meta;
 	let t = TInst (c,[]) in
 	match flags with
 	| [] -> n, t