Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351346 - [validation] Check instanceof for type inference
Summary: [validation] Check instanceof for type inference
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-06 11:35 EDT by Klaus Reimer CLA
Modified: 2013-06-19 11:11 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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