| Summary: | [xbase] [compiler] better common type inference for typeof expressions | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Knut Wannheden <knut.wannheden> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | sebastian.zarnekow, sven.efftinge |
| Version: | 2.0.0 | Flags: | sven.efftinge:
indigo+
|
| Target Milestone: | M7 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
Pushed to master. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
It would be nice if the "common type inference" would derive Class<?> as the common type for multiple typeof expressions. E.g. the following Xtend2 snippet: test(Object a) { switch a { case null:typeof(Test) case a:typeof(Void) } } is compiled to: public Object test(final Object a) { Object _switchResult = null; final Object a_1 = a; boolean matched = false; if (!matched) { if (org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_equals(a_1,null)) { matched=true; _switchResult = Test.class; } } if (!matched) { if (org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_equals(a_1,a)) { matched=true; _switchResult = java.lang.Void.class; } } return _switchResult; } Note that the type inferred is Object and not Class<?>. The same can be observed with dispatch functions: dispatch foo(Void o) { typeof(Test) } dispatch foo(Integer o) { typeof(Integer) } results in: public Object _foo(final Void o) { return Test.class; } public Object _foo(final Integer o) { return java.lang.Integer.class; }