record type could be inside a union type, extract it from there first.
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java
index 351a52e..9799dff 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/validation/TypeInfoValidator.java
@@ -1313,8 +1313,6 @@
TypeCompatibility result = TypeCompatibility.TRUE;
for (int i = 0; i < testTypesSize; i++) {
final IValueReference argument = arguments[i];
- final IRType argumentType = JavaScriptValidations
- .typeOf(argument);
final IRParameter parameter = parameters.get(i);
if (parameter.getType() instanceof IRTypeExtension) {
final IValidationStatus status = ((IRTypeExtension) parameter
diff --git a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java
index a32c892..61d6fee 100644
--- a/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java
+++ b/plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/javascript/typeinfo/RTypes.java
@@ -275,7 +275,15 @@
public static IRRecordType recordType(@Nullable IValueReference argument) {
if (argument != null) {
final Set<String> directChildren = argument.getDirectChildren();
- final IRType type = JavaScriptValidations.typeOf(argument);
+ IRType type = JavaScriptValidations.typeOf(argument);
+ if (type instanceof IRUnionType) {
+ for (IRType unionTarget : ((IRUnionType) type).getTargets()) {
+ if (unionTarget instanceof IRRecordType) {
+ type = unionTarget;
+ break;
+ }
+ }
+ }
if (type instanceof IRRecordType) {
if (directChildren.isEmpty()) {
return (IRRecordType) type;
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 72f605c..899abb1 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
@@ -2915,4 +2915,34 @@
List<IProblem> validate = validate(code.toString());
assertEquals(1, validate.size());
}
+
+ public void testRecordTypeWrappedInUnion() {
+ final StringList code = new StringList();
+
+ code.add("/**");
+ code.add("* @return {{test:String,test2:Number}}");
+ code.add("*/");
+ code.add("function test() {");
+ code.add(" /** @type {{test:String,test2:Number}} */");
+ code.add(" var x = new Object();");
+ code.add(" x.test = '';");
+ code.add(" x.test2 = 2;");
+ code.add(" return x;");
+ code.add("}");
+
+ code.add("function caller() {");
+ code.add(" var x = test();");
+ code.add(" reciever(x);");
+ code.add("}");
+
+ code.add("/**");
+ code.add("* @param {{test:String,test2:Number}} y");
+ code.add("*/");
+ code.add("function reciever(y) {");
+ code.add("}");
+ List<IProblem> validate = validate(code.toString());
+ assertEquals(0, validate.size());
+
+ }
+
}