Skip to content

StackOverflowError when using Java code that creates types with LazyRef #21521

Closed
@wjoel

Description

@wjoel

Compiler version

3.5.0, works on 3.4.2, 3.4.3.

Minimized code

I have unfortunately not been able to minimize this to a self contained example.

//> using scala 3.5.0
//> using dep io.github.jwharm.javagi:gtk:0.10.2

import org.gnome.gtk.{Unit as _, *}

object Main {
  Box.builder()
    .setOrientation(Orientation.VERTICAL)
    .setHalign(Align.START)
    .setValign(Align.BASELINE)
    .se
    .build()
    .asInstanceOf[Box]
}

Note that .se (which does not exist, and should be a compiler error) is intentional, and triggers the stack overflow.
Scala 3.4.2 fails with a reasonable error message:

 7 |  Box.builder()
 8 |    .setOrientation(Orientation.VERTICAL)
 9 |    .setHalign(Align.START)
10 |    .setValign(Align.BASELINE)
11 |    .se
   |  ^
   |  value se is not a member of org.gnome.gtk.Box#Builder[? <: org.gnome.gtk.Box#Builder[?]]#B#B² - did you mean B.ne?
   |
   |  where:    B  is a type in trait Builder² with bounds <: io.github.jwharm.javagi.gobject.Builder³[B]
   |            B² is a type in class Builder⁴ with bounds <: org.gnome.gtk.Widget#Builder⁴[B²]

Output (click arrow to expand)

  Exception while compiling /home/wjoel/dev/scala3-playground/Box.java, /home/wjoel/dev/scala3-21:47:04 [1004/45939]
, /home/wjoel/dev/scala3-playground/Orientable.java, /home/wjoel/dev/scala3-playground/Widget.java

  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Xno-enrich-error-messages.

     while compiling: <no file>
        during phase: parser
                mode: Mode()
     library version: version 2.13.14
    compiler version: version 3.5.0
            settings: -classpath /home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-l
ibrary_3/3.5.0/scala3-library_3-3.5.0.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwha
rm/javagi/gtk/0.10.2/gtk-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala
-library/2.13.14/scala-library-2.13.14.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwh
arm/javagi/gdk/0.10.2/gdk-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/ja
vagi/gsk/0.10.2/gsk-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/javagi/g
dkpixbuf/0.10.2/gdkpixbuf-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/ja
vagi/gio/0.10.2/gio-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/javagi/p
ango/0.10.2/pango-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/javagi/pan
gocairo/0.10.2/pangocairo-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwharm/ca
irobindings/cairo/1.18.3/cairo-1.18.3.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/jwha
rm/javagi/graphene/0.10.2/graphene-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/github/
jwharm/javagi/gmodule/0.10.2/gmodule-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/githu
b/jwharm/javagi/gobject/0.10.2/gobject-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io/git
hub/jwharm/javagi/harfbuzz/0.10.2/harfbuzz-0.10.2.jar:/home/wjoel/.cache/coursier/v1/https/repo1.maven.org/maven2/io
/github/jwharm/javagi/glib/0.10.2/glib-0.10.2.jar -d /home/wjoel/dev/scala3-playground/.scala-build/scala3-playgroun
d_1a8a7b68eb/classes/main -java-output-version 22 -sourceroot /home/wjoel/dev/scala3-playground

Exception in thread "main" java.lang.StackOverflowError
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.traverse(Implicits.scala:681)
        at dotty.tools.dotc.typer.ImplicitRunInfo$collectParts$2$.apply(Implicits.scala:686)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:762)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:128)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:763)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:128)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:763)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:128)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:763)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:128)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:763)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.mutable.LinkedHashSet.foreach(LinkedHashSet.scala:128)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1(Implicits.scala:757)
        at dotty.tools.dotc.typer.ImplicitRunInfo.recur$1(Implicits.scala:763)
        at dotty.tools.dotc.typer.ImplicitRunInfo.iscopeRefs$1(Implicits.scala:706)
        at dotty.tools.dotc.typer.ImplicitRunInfo.addCompanions$1(Implicits.scala:739)
        at dotty.tools.dotc.typer.ImplicitRunInfo.collectCompanions$1$$anonfun$1(Implicits.scala:757)
... and so on

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions