union fixes with assignableForm/instanceof 

literal arrays that are mixed are now created as a Union type. so that
you can call a function with a param Array<String|Number> with
["string",1]

added test for various union in union calls Number|String will fit in
Number|String|Date but not visa versa

of just a String will fit in a Number|String but not visa versa
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
index 2f0482b..6057d50 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/ti/TypeInferencerVisitor.java
@@ -256,8 +256,13 @@
 		if (types.isEmpty()) {
 			return new ConstantValue(RTypes.arrayOf());
 		} else {
-			return new ConstantValue(RTypes.arrayOf(context,
-					CommonSuperTypeFinder.evaluate(context, types)));
+			if (types.size() == 1) {
+				return new ConstantValue(RTypes.arrayOf(context,
+						CommonSuperTypeFinder.evaluate(context, types)));
+			} else {
+				return new ConstantValue(RTypes.arrayOf(context,
+						RTypes.union(types)));
+			}
 		}
 	}
 
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RType.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RType.java
index 785a03d..b4e7ff0 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RType.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RType.java
@@ -36,10 +36,11 @@
 			return TypeCompatibility.FALSE;
 		} else if (type instanceof RUnionType) {
 			for (IRType part : ((RUnionType) type).targets) {
-				if (isAssignableFrom(part).ok()) {
-					return TypeCompatibility.TRUE;
+				if (!isAssignableFrom(part).ok()) {
+					return TypeCompatibility.FALSE;
 				}
 			}
+			return TypeCompatibility.TRUE;
 		}
 		return TypeCompatibility.FALSE;
 	}
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RUnionType.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RUnionType.java
index aea40af..2a4c209 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RUnionType.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RUnionType.java
@@ -38,6 +38,13 @@
 
 	@Override
 	public TypeCompatibility isAssignableFrom(IRType type) {
+		if (type instanceof IRUnionType) {
+			Set<IRType> targets = ((IRUnionType) type).getTargets();
+			if (this.targets.containsAll(targets)) {
+				return TypeCompatibility.TRUE;
+			}
+			return TypeCompatibility.FALSE;
+		}
 		for (IRType target : targets) {
 			if (target.isAssignableFrom(type).ok()) {
 				return TypeCompatibility.TRUE;
diff --git a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/typeinference/TypeInferenceTests.java b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/typeinference/TypeInferenceTests.java
index 56258b4..a4a2d64 100644
--- a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/typeinference/TypeInferenceTests.java
+++ b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/typeinference/TypeInferenceTests.java
@@ -1113,7 +1113,7 @@
 		IValueCollection collection = inference(code.toString());
 		IValueReference child = collection.getChild("x");
 		IRType type = JavaScriptValidations.typeOf(child);
-		assertEquals(RTypes.arrayOf(ts(), RTypes.OBJECT), type);
+		assertEquals(RTypes.arrayOf(ts(), RTypes.union(Arrays.<IRType>asList(RTypes.STRING,RTypes.NUMBER))), type);
 	}
 
 	public void testArrayInitializerWithVariableNumbers() {
diff --git a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java
index 6b8c4aa..167ba33 100644
--- a/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java
+++ b/tests/org.eclipse.dltk.javascript.core.tests/src/org/eclipse/dltk/javascript/core/tests/validation/TypeInfoValidationTests.java
@@ -2193,28 +2193,28 @@
 		final List<IProblem> problems = validate(code.toString());
 		assertEquals(problems.toString(), 0, problems.size());
 	}
-	
-		public void testFunctionFromParamType() {
-		final StringList code = new StringList();
-		code.add("/** @param {function(String)} obj */");
-		code.add("function y(obj) {");
-		code.add("  obj('');");
-		code.add("}");
-		final List<IProblem> problems = validate(code.toString());
-		assertEquals(problems.toString(), 0, problems.size());
-	}
-	
-	public void testFunctionCallFromUnion() {
-		final StringList code = new StringList();
-		code.add("/** @param {function(String)|String} obj */");
-		code.add("function y(obj) {");
-		code.add("  obj('');");
-		code.add("}");
-		final List<IProblem> problems = validate(code.toString());
-		assertEquals(problems.toString(), 0, problems.size());
-	}
 
-	public void testUnionParamTypeCompatibility() {
+	public void testFunctionFromParamType() {
+	final StringList code = new StringList();
+	code.add("/** @param {function(String)} obj */");
+	code.add("function y(obj) {");
+	code.add("  obj('');");
+	code.add("}");
+	final List<IProblem> problems = validate(code.toString());
+	assertEquals(problems.toString(), 0, problems.size());
+}
+
+public void testFunctionCallFromUnion() {
+	final StringList code = new StringList();
+	code.add("/** @param {function(String)|String} obj */");
+	code.add("function y(obj) {");
+	code.add("  obj('');");
+	code.add("}");
+	final List<IProblem> problems = validate(code.toString());
+	assertEquals(problems.toString(), 0, problems.size());
+}
+
+	public void testUnionParamTypeCompatibility1() {
 		final StringList code = new StringList();
 		code.add("/** @param {{name:String}} person */");
 		code.add("function test(person) {}");
@@ -2224,8 +2224,76 @@
 		code.add("  test({ name: obj });");
 		code.add("}");
 		final List<IProblem> problems = validate(code.toString());
+		assertEquals(problems.toString(), 1, problems.size());
+	}
+	
+
+	
+	public void testUnionParamTypeCompatibility2() {
+		final StringList code = new StringList();
+		code.add("/** @param {String|Number} person */");
+		code.add("function test(person) {}");
+		code.add("");
+		code.add("/** @param {String|Number} obj */");
+		code.add("function y(obj) {");
+		code.add("  test(obj);");
+		code.add("}");
+		final List<IProblem> problems = validate(code.toString());
 		assertEquals(problems.toString(), 0, problems.size());
 	}
+	
+	public void testUnionParamTypeCompatibility3() {
+		final StringList code = new StringList();
+		code.add("/** @param {String|Number} person */");
+		code.add("function test(person) {}");
+		code.add("");
+		code.add("/** @param {String|Number|Date} obj */");
+		code.add("function y(obj) {");
+		code.add("  test(obj);");
+		code.add("}");
+		final List<IProblem> problems = validate(code.toString());
+		assertEquals(problems.toString(), 1, problems.size());
+	}
+	
+	public void testUnionParamTypeCompatibility4() {
+		final StringList code = new StringList();
+		code.add("/** @param {String|Number|Date} person */");
+		code.add("function test(person) {}");
+		code.add("");
+		code.add("/** @param {String|Number} obj */");
+		code.add("function y(obj) {");
+		code.add("  test(obj);");
+		code.add("}");
+		final List<IProblem> problems = validate(code.toString());
+		assertEquals(problems.toString(), 0, problems.size());
+	}
+	
+	public void testUnionParamTypeCompatibility5() {
+		final StringList code = new StringList();
+		code.add("/** @param {String|Number|Date} person */");
+		code.add("function test(person) {}");
+		code.add("");
+		code.add("/** @param {Number} obj */");
+		code.add("function y(obj) {");
+		code.add("  test(obj);");
+		code.add("}");
+		final List<IProblem> problems = validate(code.toString());
+		assertEquals(problems.toString(), 0, problems.size());
+	}
+	
+	public void testUnionParamTypeCompatibility6() {
+		final StringList code = new StringList();
+		code.add("/** @param {Number} person */");
+		code.add("function test(person) {}");
+		code.add("");
+		code.add("/** @param {String|Number|Date} obj */");
+		code.add("function y(obj) {");
+		code.add("  test(obj);");
+		code.add("}");
+		final List<IProblem> problems = validate(code.toString());
+		assertEquals(problems.toString(), 1, problems.size());
+	}
+
 
 	public void testArrayLookupWithUnknowVariables() {
 		final StringList code = new StringList();