| Summary: | [Xtend] Array Conversion fails | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Jason Barkanic <jbarkanic> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | christian.dietrich.opensource, sebastian.zarnekow, sven.efftinge |
| Version: | unspecified | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | SR2 | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
In my case, the following was the actual behavior I desired.
var Iterable<String> a = 'a,b,c'.split(',')
a = a.tail
which avoids conversion back to array:
String[] _split = "a,b,c".split(",");
Iterable<String> a = ((Iterable<String>)Conversions.doWrapArray(_split));
Iterable<String> _tail = IterableExtensions.<String>tail(a);
Iterable<String> _a = a = _tail;
I'm not sure of the general solution, but currently there seems to be no way to tell when array conversion should or shouldn't work.
Which build do you use? Hello Sebastian, the problem even occurs with build 2.1.0.v201110141320 thus i asken Jason to file a bug. Regards Christian It's related to bug 345955. I tried with two different builds, one from Oct. 12 and the latest stable and it generated correctly working code in both cases. @Christian could you please double check and reopen if you really get it with the latest builds? I created following Test class:
class BugTest {
@org.junit.Test
def void test() {
var a = 'a,b,c'.split(',')
a = a.tail
}
}
it fails with 2.1.0.v201110141320. somehow i cannot reopen this bug. buzilla doesnt let me ;-)
@SuppressWarnings("all")
public class BugTest {
@Test
public void test() {
String[] _split = "a,b,c".split(",");
String[] a = _split;
final String[] typeConverted_a = (String[])a;
Iterable<String> _tail = IterableExtensions.<String>tail(((Iterable<String>)Conversions.doWrapArray(typeConverted_a)));
a = ((String[])Conversions.unwrapArray(_tail));
}
}
java.lang.ClassCastException: org.eclipse.xtext.xbase.lib.IterableExtensions$2 cannot be cast to [Ljava.lang.String;
at test.mm.BugTest.test(BugTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
See last comment We have to pass the String[].class into the conversion routine since this information is not available at runtime but only statically at compile time. See also the ticket that's mentioned in comment #4 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 |
Build Identifier: var a = 'a,b,c'.split(',') a = a.tail Validates and compiles but causes a cast exception on the second line. In this case the call to IterableExtensions.tail wraps the already wrapped array, so it doesn't know how to unwrap it afterward. The compiled code: String[] _split = "a,b,c".split(","); String[] a = _split; final String[] typeConverted_a = (String[])a; Iterable<String> _tail = IterableExtensions.<String>tail(((Iterable<String>)Conversions.doWrapArray(typeConverted_a))); a = ((String[])Conversions.unwrapArray(_tail)); Reproducible: Always