if you override a super class function (@extends {baseObject}) this
should not generate a warning.
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 793394b..74ef653 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
@@ -49,6 +49,7 @@
import org.eclipse.dltk.internal.javascript.ti.ConstantValue;
import org.eclipse.dltk.internal.javascript.ti.IReferenceAttributes;
import org.eclipse.dltk.internal.javascript.ti.ITypeInferenceContext;
+import org.eclipse.dltk.internal.javascript.ti.IValue;
import org.eclipse.dltk.internal.javascript.ti.JSMethod;
import org.eclipse.dltk.internal.javascript.ti.TypeInferencer2;
import org.eclipse.dltk.internal.javascript.ti.TypeInferencerVisitor;
@@ -1783,9 +1784,17 @@
assign.problemMessage(), node.sourceStart(),
node.sourceEnd());
} else if (reference.getKind() == ReferenceKind.FUNCTION) {
+ // test if it is not a function override of a super local type class.
+ Set<String> directChildren = null;
+ if (reference.getParent() != null)
+ directChildren = reference.getParent().getDirectChildren(
+ IValue.NO_LOCAL_TYPES);
+ if (directChildren == null
+ || directChildren.contains(reference.getName())) {
reporter.reportProblem(JavaScriptProblems.UNASSIGNABLE_ELEMENT,
ValidationMessages.UnassignableFunction,
node.sourceStart(), node.sourceEnd());
+ }
}
}
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 a2fbf97..7340957 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
@@ -2506,7 +2506,41 @@
assertEquals(ValidationMessages.UnassignableFunction, problems.get(0)
.getMessage());
}
+
+
+ public void testAssignToFunctionInAFunction() {
+ final StringList code = new StringList();
+ code.add("function a() {}");
+ code.add("function b() {");
+ code.add(" a = 1");
+ code.add("}");
+ final List<IProblem> problems = validate(code.toString());
+ assertEquals(problems.toString(), 1, problems.size());
+ assertEquals(JavaScriptProblems.UNASSIGNABLE_ELEMENT, problems.get(0)
+ .getID());
+ assertEquals(ValidationMessages.UnassignableFunction, problems.get(0)
+ .getMessage());
+ }
+
+ public void testAssignToFunctionOfAParentClass() {
+ final StringList code = new StringList();
+ code.add("function baseObject() {");
+ code.add(" this.myPublicMethod = function() { }");
+ code.add("}");
+ code.add("/**");
+ code.add(" * @constructor");
+ code.add(" * @extends {baseObject}");
+ code.add(" */");
+ code.add("function childObject() {");
+ code.add(" this.myPublicMethod = function() { }");
+ code.add("}");
+ final List<IProblem> problems = validate(code.toString());
+ assertEquals(problems.toString(), 0, problems.size());
+ }
+
+
+
// This test will not always fail!, this is because sometimes it can map on
// String other times it maps on Number (ImmutableValue.getChild())
public void testDoubleReferences() {