Browse Source

remove obsolete special cases for type parameters of `@:to/@:from` (closes #3494)

Simon Krajewski 10 years ago
parent
commit
4c9febead5
3 changed files with 32 additions and 5 deletions
  1. 4 4
      std/Map.hx
  2. 27 0
      tests/unit/src/unit/issues/Issue3494.hx
  3. 1 1
      typeload.ml

+ 4 - 4
std/Map.hx

@@ -134,19 +134,19 @@ abstract Map<K,V>(IMap<K,V> ) {
 		return v;
 	}
 
-	@:to static inline function toStringMap(t:IMap<String,V>):StringMap<V> {
+	@:to static inline function toStringMap<V>(t:IMap<String,V>):StringMap<V> {
 		return new StringMap<V>();
 	}
 
-	@:to static inline function toIntMap(t:IMap<Int,V>):IntMap<V> {
+	@:to static inline function toIntMap<V>(t:IMap<Int,V>):IntMap<V> {
 		return new IntMap<V>();
 	}
 
-	@:to static inline function toEnumValueMapMap<K:EnumValue>(t:IMap<K,V>):EnumValueMap<K,V> {
+	@:to static inline function toEnumValueMapMap<K:EnumValue,V>(t:IMap<K,V>):EnumValueMap<K,V> {
 		return new EnumValueMap<K, V>();
 	}
 
-	@:to static inline function toObjectMap<K:{ }>(t:IMap<K,V>):ObjectMap<K,V> {
+	@:to static inline function toObjectMap<K:{ },V>(t:IMap<K,V>):ObjectMap<K,V> {
 		return new ObjectMap<K, V>();
 	}
 

+ 27 - 0
tests/unit/src/unit/issues/Issue3494.hx

@@ -5,10 +5,37 @@ private abstract E2<T1,T2>(Dynamic)
 	to T1 to T2 to E2<T2,T1>
 {}
 
+private abstract E3<T1,T2>(Dynamic)
+from T1 from T2
+to T1 to T2
+{
+    @:from inline static public function _from2<T1, T2, _T1:E3<T1,T2>, _T2:E3<T1,T2>>(e:E3<_T1,_T2>):E3<T1,T2> {
+        return untyped e;
+    }
+}
+
 class Issue3494 extends Test {
 	function test() {
         var v1:E2<Int,String> = 1;
         var v2:E2<String,Int> = 2;
         v1 = v2;
+		eq(2, v1);
+		eq(2, v2);
+	}
+
+	function test2() {
+        var v1:E3<Int,String> = 1;
+        var v2:E3<String,Int> = 2;
+        v1 = v2;
+		eq(2, v1);
+		eq(2, v2);
+	}
+
+	function test3() {
+        var v1:E3<Int,String> = 1;
+        var v2:E3<String,Int> = 2;
+        v1 = E3._from2(v2);
+		eq(2, v1);
+		eq(2, v2);
 	}
 }

+ 1 - 1
typeload.ml

@@ -1949,7 +1949,7 @@ let init_class ctx c p context_init herits fields =
 			let dynamic = List.mem ADynamic f.cff_access || (match parent with Some { cf_kind = Method MethDynamic } -> true | _ -> false) in
 			if inline && dynamic then error (f.cff_name ^ ": You can't have both 'inline' and 'dynamic'") p;
 			ctx.type_params <- (match c.cl_kind with
-				| KAbstractImpl a when Meta.has Meta.Impl f.cff_meta || Meta.has Meta.From f.cff_meta || Meta.has Meta.MultiType a.a_meta && Meta.has Meta.To f.cff_meta ->
+				| KAbstractImpl a when Meta.has Meta.Impl f.cff_meta ->
 					params @ a.a_params
 				| _ ->
 					if stat then params else params @ ctx.type_params);