scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.81k stars 1.05k forks source link

Cyclic reference error when using doc but not compile #14059

Closed keirlawson closed 1 year ago

keirlawson commented 2 years ago

Compiler version

3.1.0

Minimized code

Based on https://github.com/chadselph/reproduce-dotty-cyclical-error

package example

import software.amazon.awssdk.services.cloudwatchlogs.model.GetLogEventsRequest

object DottyCylicalRefError {

  GetLogEventsRequest
    .builder()
    .limit(0)
}

Output

sbt:root> doc
[info] Main Scala API documentation to /home/keirlawson/Code/reproduce-dotty-cyclical-error/target/scala-3.1.0/api...
exception caught when loading trait Builder: Cyclic reference involving object GetLogEventsRequest
exception caught when loading module class GetLogEventsRequest$: Cyclic reference involving object GetLogEventsRequest
Cyclic reference involving object GetLogEventsRequest while compiling /home/keirlawson/Code/reproduce-dotty-cyclical-error/target/scala-3.1.0/classes/example/DottyCylicalRefError.tasty

Expectation

No cyclic reference as compile passes fine.

pikinier20 commented 2 years ago

This bug is not directly related to doctool. The problem lies in compilation from tasty which is run by Scaladoc under the hood. Running the following command:

scalac -classpath <classpath_from_sbt> --from-tasty target/scala-3.1.2-RC1-bin-20211213-8e1054e-NIGHTLY/classes/example/DottyCylicalRefError.tasty

produces the same error:

exception caught when loading trait Builder: Cyclic reference involving object GetLogEventsRequest
exception caught when loading module class GetLogEventsRequest$: Cyclic reference involving object GetLogEventsRequest
Cyclic reference involving object GetLogEventsRequest while compiling target/scala-3.1.2-RC1-bin-20211213-8e1054e-NIGHTLY/classes/example/DottyCylicalRefError.tasty
Exception in thread "main" dotty.tools.dotc.core.CyclicReference: 
        at dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:155)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:166)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
        at dotty.tools.dotc.core.classfile.ClassfileParser$innerClasses$.getMember$1(ClassfileParser.scala:1060)
        at dotty.tools.dotc.core.classfile.ClassfileParser$innerClasses$.classSymbol(ClassfileParser.scala:1072)
        at dotty.tools.dotc.core.classfile.ClassfileParser.classNameToSymbol(ClassfileParser.scala:114)
        at dotty.tools.dotc.core.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:396)
        at dotty.tools.dotc.core.classfile.ClassfileParser.processTypeArgs$1(ClassfileParser.scala:383)
        at dotty.tools.dotc.core.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:398)
        at dotty.tools.dotc.core.classfile.ClassfileParser.dotty$tools$dotc$core$classfile$ClassfileParser$$sigToType(ClassfileParser.scala:522)
        at dotty.tools.dotc.core.classfile.ClassfileParser$AttributeCompleter.complete(ClassfileParser.scala:665)
        at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:190)
        at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
        ...