Bug 359416 - [content assist] Member variable type lost after ?: assignment
Summary: [content assist] Member variable type lost after ?: assignment
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-29 09:02 EDT by Ingo Rau CLA
Modified: 2013-06-28 04:10 EDT (History)
1 user (show)

See Also:


Attachments
Test class (560 bytes, application/x-javascript)
2011-09-29 09:03 EDT, Ingo Rau CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ingo Rau CLA 2011-09-29 09:02:25 EDT
Build Identifier: 20110916-0149, JSDT: 1.3.1.v20110810

The type of a member variable is lost if it is assigned via the ?: operator:

/** @type Number */
this.value = (condition) ? 1 : 0;

Obviously, sometimes the result of ?: is ambigous, so the type must be "any", but in such a case, it isn't. And especially, the @type markup should have precedence - if the programmer tells JSDT, what type the variable has, it should be treated like this.

Reproducible: Always

Steps to Reproduce:
1.Copy attached file into an Eclipse workspace
2.Hover mouse over both "toFixed(2)" statements
3.Enter "this._default2." and press Ctrl-Space -> nothing happens (unlike with _default1)
Comment 1 Ingo Rau CLA 2011-09-29 09:03:39 EDT
Created attachment 204287 [details]
Test class
Comment 2 Vincent TARDIF CLA 2013-06-28 04:10:31 EDT
This bug also allows the compiler to accept a null assignment to a primitive type. (findbugs marks the line with the warning "Possible indirection of a null pointer"). Although a NullPointerException is thrown at execution.

Example code : 

public class TestClass {
	public static void main(String[] args) {
		Object tmp = null;
		double a = tmp == null ? null : 0.;
	}
}