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

Bug 350537

Summary: [validation] Type mismatch when rewriting an object
Product: [WebTools] JSDT Reporter: Dusan Smolnikar <dusan.smolnikar>
Component: GeneralAssignee: Chris Jaun <cmjaun>
Status: RESOLVED FIXED QA Contact: Nitin Dahyabhai <thatnitind>
Severity: minor    
Priority: P3 CC: cmjaun
Version: unspecifiedFlags: thatnitind: review+
Target Milestone: 3.2.5   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
patch none

Description Dusan Smolnikar CLA 2011-06-28 05:37:42 EDT
Build Identifier: 20110407183333

Enter the following code into a .js file:
-----
// Create objects
var foo = {
	bar : {}
};

// Set some properties
foo.bar.one = 1;
foo.bar.two = 2;

// Reset the object
foo.bar = {};
-----

On the last line, I will get a javascript warning:
Type mismatch: cannot convert from ___anonymous346782_346783 to ___anonymous346761_346762

There doesn't seem to be anything wrong with the code. I am simply overwriting an object with a new object.

If, however, I do the following:
-----
...
// Reset the object
foo.bar = new Object();
-----

I do not get a warning. From my understanding of javascript, the two declarations are equivalent.

Reproducible: Always

Steps to Reproduce:
In eclipse preferences go to:
JavaScript > Validator > Error/Warnings
and enable JavaScript semantic validation.

This will enable display of warnings, such as described above.
Comment 1 Chris Jaun CLA 2011-06-29 15:15:33 EDT
Created attachment 198856 [details]
patch

Removes error reported for mis-matched types on assignment statements.

Anything can be assigned to anything in JavaScript, no need for such checking.
Comment 2 Chris Jaun CLA 2011-07-01 10:42:49 EDT
Checked into 3.2.5 and HEAD.