Browse Source

don't accept next/hasNext forwarded from `@:forward abstract A(Dynamic)` for iteration (#4705, #7363)

Aleksandr Kuzmenko 6 years ago
parent
commit
54c705e0b4

+ 5 - 0
src/typing/forLoop.ml

@@ -192,6 +192,11 @@ module IterationKind = struct
 				let e_tmp = make_local v_tmp v_tmp.v_pos in
 				let acc_next = type_field type_field_config ctx e_tmp "next" p MCall in
 				let acc_hasNext = type_field type_field_config ctx e_tmp "hasNext" p MCall in
+				(match acc_next, acc_hasNext with
+					| AKExpr({ eexpr = TField(_, FDynamic _)}), _
+					| _, AKExpr({ eexpr = TField(_, FDynamic _)}) -> raise Not_found
+					| _ -> ()
+				);
 				let e_next = !build_call_ref ctx acc_next [] WithType.value e.epos in
 				let e_hasNext = !build_call_ref ctx acc_hasNext [] WithType.value e.epos in
 				IteratorAbstract(v_tmp,e_next,e_hasNext),e,e_next.etype

+ 11 - 0
tests/misc/projects/Issue7363/Main.hx

@@ -4,6 +4,10 @@ class Main {
 		for (field in a) {
 			trace (field);
 		}
+		var a:ForwardedObject = { foo: 12, bar: "13" };
+		for (field in a) {
+			trace (field);
+		}
 	}
 }
 
@@ -11,4 +15,11 @@ abstract Object(Dynamic) from Dynamic to Dynamic {
 	public inline function new () {
 		this = { };
 	}
+}
+
+@:forward
+abstract ForwardedObject(Dynamic) from Dynamic to Dynamic {
+	public inline function new () {
+		this = { };
+	}
 }

+ 2 - 1
tests/misc/projects/Issue7363/compile-fail.hxml.stderr

@@ -1 +1,2 @@
-Main.hx:4: characters 17-18 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
+Main.hx:4: characters 17-18 : You can't iterate on a Dynamic value, please specify Iterator or Iterable
+Main.hx:8: characters 17-18 : You can't iterate on a Dynamic value, please specify Iterator or Iterable