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

Bug 359416

Summary: [content assist] Member variable type lost after ?: assignment
Product: [WebTools] JSDT Reporter: Ingo Rau <ingo.rau>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: NEW --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: vincent.tardif
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test class none

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.;
	}
}