Browse Source

[java] fix Std.is for non-reference and unrelated types (fixes #5168, #6823)

Aleksandr Kuzmenko 6 years ago
parent
commit
4dfeb9dfa2
2 changed files with 18 additions and 1 deletions
  1. 10 1
      src/generators/genjava.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue5168.hx

+ 10 - 1
src/generators/genjava.ml

@@ -198,6 +198,10 @@ let mk_cast_if_needed t_to e =
 	else
 		mk_cast t_to e
 
+let is_reference_type t =
+	match Abstract.follow_with_abstracts t with
+	| TAbstract _ -> false
+	| _ -> true
 
 (* ******************************************* *)
 (* JavaSpecificESynf *)
@@ -305,7 +309,12 @@ struct
 								| _ -> { e with eexpr = TBlock([run obj; { e with eexpr = TConst(TBool true) }]) }
 							)
 						| _ ->
-							mk_is false obj md
+							if is_reference_type obj.etype then
+								try
+									Type.unify obj.etype (type_of_module_type md);
+									mk_is false obj md
+								with Unify_error _ -> e
+							else e
 					)
 				(* end Std.is() *)
 				| _ -> Type.map_expr run e

+ 8 - 0
tests/unit/src/unit/issues/Issue5168.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue5168 extends unit.Test {
+	function test() {
+		f(Std.is("hello", Issue5168));
+		f(Std.is(1, String));
+	}
+}