scala / scala3

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

object caps does not have a member type Cap #21107

Open jxnu-liguobin opened 2 weeks ago

jxnu-liguobin commented 2 weeks ago

I'm upgrading from 3.3.3 to 3.4.1 and after rewriting syntax I try to commit the code but the CI complained.

Compiler version

3.4.1

Minimized code

According to the logs, dotty crashes at AnalyzerException, which is just a simple code.

package bitlap.sbt.analyzer.model

import bitlap.sbt.analyzer.DependencyScopeEnum

sealed abstract class AnalyzerException(msg: String)           extends RuntimeException(msg)
final case class AnalyzerCommandNotFoundException(msg: String) extends AnalyzerException(msg)

final case class AnalyzerCommandUnknownException(
  command: String,
  moduleId: String,
  scope: DependencyScopeEnum,
  msg: String
) extends AnalyzerException(msg)

It's ok on my Mac OSX:

Output (click arrow to expand)

```scala [info] compiling 42 Scala sources and 1 Java source to /home/runner/work/intellij-sbt-dependency-analyzer/intellij-sbt-dependency-analyzer/target/scala-3.4.1/classes ... unhandled exception while running MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, checkStatic, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} on /home/runner/work/intellij-sbt-dependency-analyzer/intellij-sbt-dependency-analyzer/src/main/scala/bitlap/sbt/analyzer/model/AnalyzerException.scala 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 -Yno-enrich-error-messages. while compiling: /home/runner/work/intellij-sbt-dependency-analyzer/intellij-sbt-dependency-analyzer/src/main/scala/bitlap/sbt/analyzer/model/AnalyzerException.scala during phase: MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, checkStatic, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} mode: Mode(ImplicitsEnabled) library version: version 2.13.12 compiler version: version 3.4.1 settings: -Werror true -classpath /home/runner/work/intellij-sbt-dependency-analyzer/intellij-sbt-dependency-analyzer/target/scala-3.4.1/classes:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-scripting-compiler-embeddable/1.9.10/kotlin-scripting-compiler-embeddable-1.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/guru/nidi/graphviz-java-min-deps/0.18.1/graphviz-java-min-deps-0.18.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.5.6/logback-classic-1.5.6.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jooq/joor/0.9.15/joor-0.9.15.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-scripting-compiler-impl-embeddable/1.9.10/kotlin-scripting-compiler-impl-embeddable-1.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.9.10/kotlin-stdlib-1.9.10.jar:/home/runner/.cache/cour [error] ## Exception when compiling 43 sources to /home/runner/work/intellij-sbt-dependency-analyzer/intellij-sbt-dependency-analyzer/target/scala-3.4.1/classes [error] dotty.tools.dotc.core.TypeError$$anon$1: object caps does not have a member type Cap [error] [error] [error] dotty.tools.dotc.core.TypeError$$anon$1: object caps does not have a member type Cap [error] (Compile / compileIncremental) dotty.tools.dotc.core.TypeError$$anon$1: object caps does not have a member type Cap [error] Total time: 26 s, completed Jul 7, 2024, 5:[51](https://github.com/bitlap/intellij-sbt-dependency-analyzer/actions/runs/9825009887/job/27124625884?pr=101#step:4:52):08 AM ```
WojciechMazur commented 2 weeks ago

This should be fixed already in https://github.com/scala/scala3/pull/20493, I think it should be available in 3.5.1 but we might backport it to 3.3.4 LTS. The minimization is missing the dependencies, so I cannot confirm it yet.

Gedochao commented 2 weeks ago

@jxnu-liguobin can you help us minimise this? or at least provide us the dependencies/project configuration to reproduce this issue?

jxnu-liguobin commented 2 weeks ago

@jxnu-liguobin can you help us minimise this? or at least provide us the dependencies/project configuration to reproduce this issue?

My repo is here. You can see the details from Github Action. https://github.com/bitlap/intellij-sbt-dependency-analyzer/tree/rewrite-3.4.1-syntax

I did not reproduce it on Mac OSX, which is why I submitted an ISSUE.

Gedochao commented 2 weeks ago

We'll still need this minimised, rather than the whole repo... we'd welcome help, it may take time before someone on the maintenance team has time to dive into this.

I'm guessing the Kotlin plugin is where the imports from the snippet come from... https://index.scala-lang.org/bitlap/kotlin-plugin

WojciechMazur commented 2 weeks ago

It seems that issue originates due to specific classpath entries added by the SbtIdeaPlugin and IntellijPlugins

// build.sbt

lazy val `sbt-dependency-analyzer` = (project in file("."))
  .enablePlugins(SbtIdeaPlugin)
  .settings(
    scalaVersion := "3.4.1",
    intellijPlugins ++= Seq("com.intellij.java", "com.intellij.java-i18n", "org.intellij.scala").map(_.toPlugin),
  )
// project/plugins.sbt

addSbtPlugin("org.jetbrains" % "sbt-idea-plugin"   % "3.26.2")
// src/main/scala/AnalyzerException.scala

sealed abstract class AnalyzerException(msg: String)           extends RuntimeException(msg)
final case class AnalyzerCommandNotFoundException(msg: String) extends AnalyzerException(msg)

I'm not yet sure what exactly causes that, but I can confirm it's 3.6.0-RC1-bin-20240708-0e36424-NIGHTLY I suggest to backport https://github.com/scala/scala3/pull/20493 to 3.5.0-RC4 as the issue probably originates when trying to enter some fallback path where it tries to use non-existing caps object declared in the compiler definitions - it expects type which does not exist, it should refer to class instead