Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Canonical, @Immutable and @TupleConstructor not properly supported #421

Closed
mauromol opened this issue Jan 11, 2018 · 5 comments
Closed
Assignees
Milestone

Comments

@mauromol
Copy link

mauromol commented Jan 11, 2018

Consider this example:

import groovy.transform.TupleConstructor

@TupleConstructor
class TestRecord  {
	String foo
	String bar
}

and the following Java class:

public class Test {

	public static void main(String[] args) {
		TestRecord t = new TestRecord("a", "b");
		System.out.println(t.getFoo());
	}
}

The editor shows a compilation error on the constructor call, but not on the Project Explorer. If you run this code, it works fine at runtime, so there seems to be some discrepancy between what the compiler does and what the parser says.
The same applies if you replace @TupleConstructor with @Canonical.
However, with @Immutable all works fine instead!

@eric-milles
Copy link
Member

eric-milles commented Jan 11, 2018 via email

@eric-milles
Copy link
Member

This is the same underlying issue that is causing #175

@eric-milles
Copy link
Member

There is also a bit of dead code in Scope.getMethod that accounts for this issue in some cases. It has been disabled for a long time now.

			// GROOVY add -- give it one more chance as the ast transform may have introduced it
			// Is this the right approach?  Requires AST transforms running before this is done.
			if (methodBinding == null) {
				methodBinding = oneLastLook(currentType, selector, argumentTypes, invocationSite);
			}

	// FIXASC (M3) currently inactive; this enables getSingleton()
	// FIXASC (M3) make this switchable as it is too damn powerful
	public MethodBinding oneLastLook(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
		if (false) {
		MethodBinding[] extraMethods = receiverType.getAnyExtraMethods(selector, argumentTypes);
		if (extraMethods != null && extraMethods.length > 0) {
			return extraMethods[0];
		}
		}
		return null;
	}

@eric-milles eric-milles modified the milestones: v3.1.0, v3.0.0 Apr 19, 2018
eric-milles added a commit that referenced this issue Jun 17, 2018
@eric-milles eric-milles removed this from the v3.0.0 milestone Jul 14, 2018
@eric-milles eric-milles changed the title @TupleConstructor and @Canonical not properly supported @Canonical, @Immutable and @TupleConstructor not properly supported Oct 8, 2022
@eric-milles eric-milles self-assigned this Oct 8, 2022
@eric-milles
Copy link
Member

image

@eric-milles
Copy link
Member

image

Covers simple cases. Ready to test in next snapshot build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants