paulk-asert commented on PR #3015:
URL: https://github.com/apache/groovy/pull/3015#issuecomment-6640587300
Thanks for the review, Daniel. Taking your points in order:
1. INFERRED_TYPE dependency. typeReference only matters when this is
inferred as Class<T>, which happens only in a static context. In an instance
context it returns null, and the old path is the right one there. I checked
both contexts in dynamic, @TypeChecked and @CompileStatic modes:
- Static method, static {} initializer and closure: this::foo gives 42 in
all three modes.
- Instance context: this::foo, this::inst and this::toString give the
same results as before.
The writer doesn't read INFERRED_TYPE; it gets Class<T> from the type
chooser, so both halves agree.
2. Nested classes. testThisMethodReferenceInStaticContextOfNestedClass
covers this: this::foo inside Outer.Nested resolves to Nested::foo.
3. Native method references. this::foo compiles to the same invokedynamic
LambdaMetafactory call as C::foo; javap shows the two methods share the same
call-site entry. The native path needs no change.
4. Error wording. The message is "Failed to find class method 'inst()' for
the type: C", and the test asserts that text. It names the class, so it reads
the same as C::inst used as a Supplier.
One correction on framing: this isn't really Java alignment. Java rejects
this in a static context entirely. The goal is to make @CompileStatic agree
with dynamic Groovy and @TypeChecked, which already accept these forms.
The change also fixes two things beyond the original report:
- Compiler crash: under @TypeChecked and @CompileStatic, an instance method
referenced through this and used as a Function<C,…> crashed with "General error
during canonicalization: Index -1 out of bounds". It now compiles and works.
- Shadowed Class methods: if a class declares a static method matching a
java.lang.Class method, such as a static getName(), @CompileStatic used to pick
Class.getName() and return "C". It now calls the class's own method. That
matches dynamic Groovy, @TypeChecked, and this.getName() under @CompileStatic.
It's the only case where code that compiled before gives a different result,
and I'll mention it in the JIRA.
Also, this::new in a static context now compiles under @CompileStatic.
Dynamic Groovy and @TypeChecked already accepted it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]