Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343100 - [xbase] [compiler] better common type inference for typeof expressions
Summary: [xbase] [compiler] better common type inference for typeof expressions
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-18 04:13 EDT by Knut Wannheden CLA
Modified: 2017-09-19 17:32 EDT (History)
2 users (show)

See Also:
sven.efftinge: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Knut Wannheden CLA 2011-04-18 04:13:53 EDT
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;
  }
Comment 1 Sebastian Zarnekow CLA 2011-04-19 13:04:26 EDT
Pushed to master.
Comment 2 Karsten Thoms CLA 2017-09-19 17:20:57 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:32:15 EDT
Closing all bugs that were set to RESOLVED before Neon.0