Skip to content

Commit

Permalink
ClassfileParser: Avoid cycle when accessing companion in inner class …
Browse files Browse the repository at this point in the history
…lookup

Previously, the call to `info` on the module val could lead to a cycle since the
module val might be in the process of being completed. This commit fixes this by
only using the module class which is all we need to lookup members.

Fixes #15288.
Fixes #14059.

Co-Authored-By: Tom Grigg <tomegrigg@gmail.com>
  • Loading branch information
smarter and griggt committed Feb 10, 2023
1 parent 3d251d6 commit f77069a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1086,10 +1086,10 @@ class ClassfileParser(
if (sym == classRoot.symbol)
staticScope.lookup(name)
else {
var module = sym.companionModule
if (!module.exists && sym.isAbsent())
module = sym.scalacLinkedClass
module.info.member(name).symbol
var moduleClass = sym.registeredCompanion
if (!moduleClass.exists && sym.isAbsent())
moduleClass = sym.scalacLinkedClass
moduleClass.info.member(name).symbol
}
else if (sym == classRoot.symbol)
instanceScope.lookup(name)
Expand Down
9 changes: 9 additions & 0 deletions sbt-test/java-compat/i15288/QueryRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface CopyableBuilder<B, T> {}
interface ToCopyableBuilder<B, T> {}

public class QueryRequest implements ToCopyableBuilder<QueryRequest.Builder, QueryRequest> {
public static Builder builder() { throw new UnsupportedOperationException(); }
public interface Builder extends CopyableBuilder<Builder, QueryRequest> {
void build();
}
}
2 changes: 2 additions & 0 deletions sbt-test/java-compat/i15288/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Test:
def makeQuery = QueryRequest.builder().build()
1 change: 1 addition & 0 deletions sbt-test/java-compat/i15288/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalaVersion := sys.props("plugin.scalaVersion")
5 changes: 5 additions & 0 deletions sbt-test/java-compat/i15288/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## This could just be a pos test checked by FromTastyTests, but
## ParallelTesting#compileTastyInDir does not support test with multiple files
## currently.
> compile
> doc

0 comments on commit f77069a

Please sign in to comment.