| Summary: | [Xtend] BasicIndexOutOfBounds exception in compiler | ||
|---|---|---|---|
| Product: | [Tools] Xtend | Reporter: | Sven Efftinge <sven.efftinge> |
| Component: | Core | Assignee: | Project Inbox <xtend-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow |
| Version: | 2.2.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
|
Description
Sven Efftinge
I get this stacktrace[3]. The side-effects validation has to unpack casts.
If the casted closure is used in an assignment, the following illegal java code is produced (note the newIterable<T>) [1].
The following snippet will result in invalid code, too [2]:
var Iterable<String> x = [ Object a |
newArrayList(a.toString).iterator
].curry('')
[1]
final Function1<Object,String> _function = new Function1<Object,String>() {
public String apply(final Object a) {
String _string = a.toString();
return _string;
}
};
Iterable<String> x = ((Iterable<String>) new Iterable<T>() {
public Iterator<T> iterator() {
return _function.apply();
}
});
[2] Note the wrong type arguments and the missing final for the _curry:
final Function1<Object,Iterator<String>> _function = new Function1<Object,Iterator<String>>() {
public Iterator<String> apply(final Object a) {
String _string = a.toString();
ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(_string);
Iterator<String> _iterator = _newArrayList.iterator();
return _iterator;
}
};
Function0<Iterator<String>> _curry = FunctionExtensions.<String, Iterator<String>>curry(_function, "");
Iterable<String> x = new Iterable<String>() {
public Iterator<String> iterator() {
return _curry.apply();
}
};
[3]
java.lang.IllegalArgumentException: a closure definition does not cause any side-effects
at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:471)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:137)
at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:137)
at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:137)
at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:90)
at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.compile(Xtend2Compiler.java:356)
at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.compile(Xtend2Compiler.java:166)
at org.eclipse.xtext.xtend2.compiler.Xtend2Compiler.compile(Xtend2Compiler.java:118)
at org.eclipse.xtext.xtend2.compiler.Xtend2Generator.doGenerate(Xtend2Generator.java:46)
at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:203)
at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:154)
at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:180)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:161)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:102)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:627)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
(In reply to comment #1) > I get this stacktrace[3]. The side-effects validation has to unpack casts. Pushed to master. I don't exceptions any more but the code snippet
def something234() {
[Object a | a.toString] as Iterable<String>
}
compiles to invalid Java code without any error marker in Xtend.
fixed in the meantime Requested via bug 522520. -M. Requested via bug 522520. -M. |