scala / scala3

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

Cyclic reference involving object WebIdentityTokenFileCredentialsProvider #18423

Open ricardoitv opened 10 months ago

ricardoitv commented 10 months ago

Compiler version

3.3.0 but I've also tried with 3.2.0, 3.1.0 and 3.0.0. I couldn't reproduce it with Scala 2.13.11.

Minimized code

import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider
import java.nio.file.Paths

object Main extends App {
  WebIdentityTokenFileCredentialsProvider.builder
    .roleArn("dummy")
    .roleSessionName("Dummy")
    .webIdentityTokenFile(Paths.get("."))
    .build
}

SBT dependency:

libraryDependencies ++= List("software.amazon.awssdk" % "sts" % "2.20.69")

Repo with all the code: https://github.com/ricardoitv/cyclic-reference-involving-object/tree/without-sbt-native-packager

Output

exception caught when loading trait Builder: Cyclic reference involving object WebIdentityTokenFileCredentialsProvider
exception caught when loading module class WebIdentityTokenFileCredentialsProvider$: Cyclic reference involving object WebIdentityTokenFileCredentialsProvider

Expectation

The error is reproducible by running sbt doc but I've bumped into it when running sbt stage (sbt-native-packager version 1.9.16).

It looks similar to this issue: https://github.com/lampepfl/dotty/issues/15288

ricardoitv commented 10 months ago

Someone at my company was experimenting with the code and they found that if we extract WebIdentityTokenFileCredentialsProvider.builder into a variable, then everything works again.

So this works:

import software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider
import java.nio.file.Paths

object Main extends App {
  val builder = WebIdentityTokenFileCredentialsProvider.builder
  builder
    .roleArn("dummy")
    .roleSessionName("Dummy")
    .webIdentityTokenFile(Paths.get("."))
    .build
}