Ver código fonte

[typer] fix wonky structure typing logic

closes #10776
Simon Krajewski 2 anos atrás
pai
commit
4e72804368
3 arquivos alterados com 41 adições e 10 exclusões
  1. 1 0
      .gitignore
  2. 5 10
      src/typing/typer.ml
  3. 35 0
      tests/unit/src/unit/issues/Issue10776.hx

+ 1 - 0
.gitignore

@@ -136,3 +136,4 @@ tests/server/test.js.map
 lib.sexp
 src/compiler/version.ml
 tests/party
+tests/misc/projects/Issue10863/error.log

+ 5 - 10
src/typing/typer.ml

@@ -866,16 +866,11 @@ and type_object_decl ctx fl with_type p =
 				when not (Meta.has Meta.CoreType a.a_meta)
 					&& not (List.exists (fun t' -> shallow_eq t t') seen) ->
 				let froms = get_abstract_froms ctx a pl in
-				begin match froms with
-				| [] ->
-					(* If the abstract has no casts in the first place, we can assume plain typing (issue #10730) *)
-					ODKPlain
-				| _ ->
-					let fold = fun acc t' -> match loop (t :: seen) t' with ODKPlain -> acc | t -> t :: acc in
-					begin match List.fold_left fold [] froms with
-						| [t] -> t
-						| _ -> ODKFailed
-					end
+				let fold = fun acc t' -> match loop (t :: seen) t' with ODKPlain -> acc | t -> t :: acc in
+				begin match List.fold_left fold [] froms with
+					| [] -> ODKPlain (* If the abstract has no casts in the first place, we can assume plain typing (issue #10730) *)
+					| [t] -> t
+					| _ -> ODKFailed
 				end
 			| TDynamic (Some t) ->
 				dynamic_parameter := Some t;

+ 35 - 0
tests/unit/src/unit/issues/Issue10776.hx

@@ -0,0 +1,35 @@
+package unit.issues;
+
+import utest.Assert;
+
+@:forward
+private abstract DialogConfig(DialogConfigData) from DialogConfigData {
+	@:from static function fromRenderResult(r:RenderResult):DialogConfig
+		return {priority: 0, ui: r};
+}
+
+private typedef DialogConfigData = {
+	final priority:Int;
+	final ui:DialogUi;
+}
+
+@:callable
+private abstract DialogUi((close:() -> Void)->RenderResult) from (close:() -> Void)->RenderResult {
+	inline function new(f)
+		this = f;
+
+	@:from static function fromRenderResult(r:RenderResult)
+		return new DialogUi(_ -> r);
+}
+
+private abstract RenderResult(String) to String from String {}
+
+class Issue10776 extends Test {
+	function test() {
+		var cfg:DialogConfig = {
+			priority: 0,
+			ui: (null : RenderResult),
+		};
+		Assert.pass();
+	}
+}