Repository navigation
Fix issue with reading legal java cyclic signatures - #26775
Merged
Merged
Conversation
SolalPirelli
approved these changes
Aug 11, 2026
SolalPirelli
left a comment
Contributor
There was a problem hiding this comment.
Looks good, one small nit
| else if tpe.typeSymbol.isContainedIn(classRoot.symbol) then | ||
| // classRoot is completed - using .info is safe | ||
| // e.g. case: `class CyclicSignature<S extends CyclicSignature<S>.Nested.Deeper>` | ||
| val member = tpe.typeSymbol.asClass.info.decls.lookup(name) |
Contributor
There was a problem hiding this comment.
Suggested change
| val member = tpe.typeSymbol.asClass.info.decls.lookup(name) | |
| val member = tpe.typeSymbol.info.decls.lookup(name) |
since info is on all denotations
This includes things like: * `class CyclicSignature<S extends CyclicSignature<S>.Nested>` * `class CyclicSignature<S extends CyclicSignature<S>.Nested.Deeper>` Type parameters with self referential prefixes in bounds like these are impossible to define in scala, but can appear in java, with a reference to `java.lang.invoke.ClassSpecializer` in stdlib's MethodHandle specifically causing issues. This is fixed both in JavaParser and ClassfileParser. The behavior for analogous scala code is unchanged (it will still error out). Interestingly, this wasn't an issue in scala 2, however both parsers are quite different there, so moving solutions from scala 2 wasn't possible. Both java and scala 2 is able to read even more java signatures, like `class Foo<T extends List<Foo<T>.Inner>>`, as both seem to omit having any cyclicity checks this early. However, as far as I'm aware, actually defining an instance of such type seems impossible (even in java), so perhaps failing early is fine, and we hopefully shouldn't find such java code in the wild, since this would be more difficult to support.
jchyb
force-pushed
the
fix-26646-cycle-methodhandle
branch
from
August 11, 2026 14:00
8239e5d to
4b2d0e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This includes things like:
class CyclicSignature<S extends CyclicSignature<S>.Nested>class CyclicSignature<S extends CyclicSignature<S>.Nested.Deeper>Type parameters with self referential prefixes in bounds like these are impossible to define in scala, but can appear in java, with a reference tojava.lang.invoke.ClassSpecializerin stdlib's MethodHandle specifically causing issues.This is fixed both in JavaParser (the fix is in Checking.scala file) and ClassfileParser. The behavior for analogous scala code is unchanged (it will still error out). Interestingly, this wasn't an issue in scala 2, however both parsers are quite different there, so moving solutions from scala 2 wasn't possible.
Both java and scala 2 is able to read even more java signatures, like
class Foo<T extends List<Foo<T>.Inner>>, as both seem to omit having any cyclicity checks this early.However, as far as I'm aware, actually defining an instance of such type seems impossible (even in java), so perhaps failing early is fine, and we hopefully shouldn't find such java code in the wild, since this would be more difficult to support.
Fixes #26646
Have you relied on LLM-based tools in this contribution?
Yes, and I checked the output by reading and comprehending the code (comments are mine)
How was the solution tested?
New automated tests (
including the issue's reproducer, if applicable)Unfortunately, the reproducer is different, since the original requires a newer idk that we don't use for compilation tests yet. Hovewer, the underlying issue is still tested, and I manually checked that the original reproducer also successfully compiles now.