eclipse / xtext

Eclipse Xtext™ is a language development framework
http://www.eclipse.org/Xtext
Eclipse Public License 2.0
769 stars 321 forks source link

Maven compilation failure for array with missing generics #2304

Open chrswk opened 7 years ago

chrswk commented 7 years ago

I spent too much time chasing this error. I'm not sure what's causing it and the Xtend code that produces it compiles fine in Eclipse but fails during the Maven build. To be honest, I'm not even sure if it's the fault of Xtend or if something else is to blame.

Using:

The error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project XXX: Compilation failure
[ERROR] XXX\target\generated-sources\xtend\ch\rswk\util\macro\AllAsListTest.java:[15,139] error: incompatible types: Object cannot be converted to List<String>

I'm able to reproduce it with this simple Xtend code:

package xxx

import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture

class AllAsListTest {
    def void fail() {
        val allAsList = Futures.allAsList(#[mockService, mockService, mockService]).get
    }

    def ListenableFuture<String> mockService() {}
}

I normally just use Futures.allAsList(mockService, mockService, mockService) but I somehow messed up some calls by wrapping them in a list.

The generated Java code and the line that causes the error:

final List<String> allAsList = Futures.<String>allAsList(new ListenableFuture[] { _mockService, _mockService_1, _mockService_2 }).get();

It should probably be new ListenableFuture<String>[]? But why does Eclipse not complain about it? Is there some additional inference going on?

-Chris

cdietrich commented 7 years ago

workaround:

Futures.<String>allAsList ....

cdietrich commented 7 years ago

the reason for the different behaviour in eclipse seems to be that javac and eclipse java compiler seem to behave differently

cdietrich commented 7 years ago

and i wonder why we dont generate real varargs here:

final List<String> allAsList = Futures.allAsList( _mockService, _mockService_1, _mockService_2).get();

chrswk commented 7 years ago

Thanks for looking into it.

I'm not sure which "way" Xtend should go for when writing allAsList(#[...]), since there's the overloaded method allAsList(Iterable<? extends ListenableFuture<? extends V>> futures) that should also be compatible with Collections.unmodifiableList that I usually see from #[...]?

cdietrich commented 7 years ago

yes that might be the case so something like

val allAsList = Futures.allAsList(mockService, mockService, mockService).get would be the natural solution