Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328188 - assignment validation should allow assignment of literal null
Summary: assignment validation should allow assignment of literal null
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: b3 (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-19 19:32 EDT by Henrik Lindberg CLA
Modified: 2017-09-13 11:52 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 Henrik Lindberg CLA 2010-10-19 19:32:57 EDT
Integer a = null;
Currently results in a type mismatch error "can not convert Object to Integer".
The evaluator already copes with null assignment, so this is only a validation issue.

Unfotunately, it is not enough to only check for direct assignment of null - null values can also be part of type inference in other situations:

var a = if wtf() then null else 2;

where the common type of null and 2 (Integer) is computed.

By introducing a NullType and modifying TypeUtils.isAssignableFrom(Type, Type), and other methods dealing with type compatibility to synthetically allow assignment of null the issue should be solved.
Comment 1 Henrik Lindberg CLA 2010-10-19 21:25:00 EDT
A NullType was introduced. Tests added that checks that ["a", null, "b"] results in List<String> being inferred (and a few other tests).