Comments (10)
Thanks, this is reproducible.
from xtext-extras.
hi, can you share the producing code snippet as well?
from xtext-extras.
This seems to happen when the "Extract Method" refactoring is performed. The refactoring wants to declare an explicit return type, but the return type reference is null. We have to know under which circumstances this could happen.
Could you share more information about the refactoring context, e.g. the code snippet that you would like to extract to a method? Could this be reproduced with a simple example?
from xtext-extras.
The following code produces the same error when trying to extract a method from the body of test
.
import java.util.ArrayList
class Test {
def void test() {
val int a = 5
new ArrayList<Integer>.addAll(#[a])
}
}
from xtext-extras.
typeComputationServices.getTypeConformanceComputer().getCommonSuperType(returnTypes, owner)
of [void, boolean, boolean]
is null.
the follow up code does not exepect that
from xtext-extras.
maybe we can do something like
returnType = calculateReturnType(resolvedTypes);
if (returnType == null) {
StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(typeComputationServices, xtendClass);
returnType = owner.newReferenceTo(Void.TYPE);
}
@JanKoehnlein what do you think?
or should the getCommonSuperType be void? @svenefftinge
from xtext-extras.
The proposed change would fix the NPE, but the actual problem is that the return type is not computed correctly. Consider this file:
package test
import java.util.ArrayList
import org.eclipse.xtend.lib.annotations.Data
class Foo {
Bar thisEnd
def boolean test() {
val int a = 5
val x = '''«thisEnd.name»'''
return new ArrayList<Integer>.addAll(#[a])
}
}
@Data
class Bar {
String name
}
If you extract the two lines val x = ...`` and
return ...`, then the refactoring would now determine void as the type. This will lead to a compile error, since the extracted method has a return statement with a type expectation, but it is incompatible with the declared return type void.
from xtext-extras.
For a workaround, how about suppressing the return type declaration and disable the "Explicit declare return type" option in the dialog? Again, this would not fix the actual problem, but should be realizable in reasonable effort and would lead to compilable code.
from xtext-extras.
see #128
and eclipse/xtext-xtend#190
from xtext-extras.
merged the PRs. Thanks everyone for investigation.
from xtext-extras.
Related Issues (20)
- Try-With-Resource broken with Java 8 HOT 5
- Completely Deprecate old Generator + Fragments HOT 1
- Java Source Lang causes NPE HOT 8
- XcoreEcoreTest fails with Xtext 2.20
- xtext-extras compilation fails HOT 7
- Late JvmMember initialization not working HOT 7
- Type parameter in methods from generic interfaces are not translated correctly HOT 4
- Wrong scoping with inferred inner classes
- Inconsistent handling of synthetic fragment for missing obj HOT 19
- AbstractClassMirror.findMember(EObject, String) fails when inner class is used in signature of member before HOT 6
- StandaloneBuilder should provide more information in case of problems HOT 1
- testMemberCount_16 fails with java 17 (and maybe also 16) HOT 1
- Avoid empty lines with two spaces between members HOT 17
- Since Java 15: Unable to reference Java types in the same project HOT 11
- Xbase languages do not correctly track imported names HOT 3
- Support incremental builds via the StandaloneBuilder HOT 3
- XbaseCompiler should be more resilient against broken code
- StandaloneBuilderTest flaky/does not work on Linux HOT 5
- StandaloneBuilder leads to test error in xtext-eclipse with tycho 2x.
- Move to Maven/Tycho for projects and build infrastructure HOT 26
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtext-extras.