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

Bug 343100

Summary: [xbase] [compiler] better common type inference for typeof expressions
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.0.0Flags: sven.efftinge: indigo+
Target Milestone: M7   
Hardware: All   
OS: All   
Whiteboard:

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