Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 351346

Summary: [validation] Check instanceof for type inference
Product: [WebTools] JSDT Reporter: Klaus Reimer <k>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: NEW --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Klaus Reimer CLA 2011-07-06 11:35:09 EDT
Build Identifier: I20110613-1736

In the following code Eclipse reports a "Type mismatch: cannot convert from A to B" warning for the "return a" statement:

    /**
     * @constructor
     */
    function A();
    
    /**
     * @constructor
     * @extends A
     */
    function B();
    
    /**
     * @param {A} a
     * @return {B}
     */
    function test(a)
    {
        if (a instanceof B) return a;
        return null;
    }

This is wrong because "a" can also be an instance of class "B" (which extends class A and is therefor a valid parameter for the function "test"). Eclipse should check at least simple if-instanceof-statements in the code to correctly determine the type of a variable.

Reproducible: Always