Code Monkey home page Code Monkey logo

Comments (10)

kthoms avatar kthoms commented on September 17, 2024 1

Thanks, this is reproducible.

from xtext-extras.

cdietrich avatar cdietrich commented on September 17, 2024

hi, can you share the producing code snippet as well?

from xtext-extras.

kthoms avatar kthoms commented on September 17, 2024

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.

tivervac avatar tivervac commented on September 17, 2024

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.

cdietrich avatar cdietrich commented on September 17, 2024

typeComputationServices.getTypeConformanceComputer().getCommonSuperType(returnTypes, owner) of [void, boolean, boolean] is null.

the follow up code does not exepect that

from xtext-extras.

cdietrich avatar cdietrich commented on September 17, 2024

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.

kthoms avatar kthoms commented on September 17, 2024

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.

kthoms avatar kthoms commented on September 17, 2024

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.

svenefftinge avatar svenefftinge commented on September 17, 2024

see #128
and eclipse/xtext-xtend#190

from xtext-extras.

svenefftinge avatar svenefftinge commented on September 17, 2024

merged the PRs. Thanks everyone for investigation.

from xtext-extras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.