Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined error if enable coverage #21695

Open
xuwei-k opened this issue Oct 2, 2024 · 3 comments
Open

undefined error if enable coverage #21695

xuwei-k opened this issue Oct 2, 2024 · 3 comments
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html compat:java itype:bug

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Oct 2, 2024

Compiler version

  • 3.5.2-RC1
  • 3.6.0-RC1-bin-20241001-8244d67-NIGHTLY

Minimized code

build.sbt

scalacOptions ++= Seq("-coverage-out:coverage-out")

libraryDependencies += "io.grpc" % "grpc-services" % "1.68.0"

scalaVersion := "3.5.2-RC1"

MyServer.scala

package example

import io.grpc.Server
import io.grpc.ServerBuilder
import io.grpc.ServerInterceptors
import io.grpc.ServerServiceDefinition
import io.grpc.protobuf.services.ProtoReflectionService
import io.grpc.util.TransmitStatusRuntimeExceptionInterceptor

object MyServer {

  def createServer(port: Int, services: List[ServerServiceDefinition]): Server = {
    services
      .foldLeft(ServerBuilder.forPort(port))((builder, service) =>
        builder.addService(
          ServerInterceptors.intercept(
            service,
            TransmitStatusRuntimeExceptionInterceptor.instance()
          )
        )
      )
      .addService(ProtoReflectionService.newInstance())
      .build()
  }

}

Output (click arrow to expand)

[error] -- Error: scala3-coverage-bug/MyServer.scala:23:12 ----------------
[error] 13 |    services
[error] 14 |      .foldLeft(ServerBuilder.forPort(port))((builder, service) =>
[error] 15 |        builder.addService(
[error] 16 |          ServerInterceptors.intercept(
[error] 17 |            service,
[error] 18 |            TransmitStatusRuntimeExceptionInterceptor.instance()
[error] 19 |          )
[error] 20 |        )
[error] 21 |      )
[error] 22 |      .addService(ProtoReflectionService.newInstance())
[error] 23 |      .build()
[error]    |    ^
[error]    |undefined: {
[error]    |  val $3$: io.grpc.ServerBuilder[?] =
[error]    |    {
[error]    |      val z$1: io.grpc.ServerBuilder[?] =
[error]    |        {
[error]    |          scala.runtime.coverage.Invoker.invoked(3, "coverage-out")
[error]    |          io.grpc.ServerBuilder.forPort(port)
[error]    |        }
[error]    |      val op$1:
[error]    |        ((io.grpc.ServerBuilder[?], io.grpc.ServerServiceDefinition) =>
[error]    |          io.grpc.ServerBuilder[?])
[error]    |       =
[error]    |        {
[error]    |          def $anonfun(builder: io.grpc.ServerBuilder[?],
[error]    |            service: io.grpc.ServerServiceDefinition): io.grpc.ServerBuilder[?]
[error]    |             =
[error]    |            {
[error]    |              val $2$: io.grpc.ServerServiceDefinition =
[error]    |                {
[error]    |                  val $1$: Seq[io.grpc.ServerInterceptor] =
[error]    |                    [
[error]    |                      {
[error]    |                        scala.runtime.coverage.Invoker.invoked(6, "coverage-out"
[error]    |                          )
[error]    |                        io.grpc.util.TransmitStatusRuntimeExceptionInterceptor.
[error]    |                          instance()
[error]    |                      }
[error]    |                     : io.grpc.ServerInterceptor]
[error]    |                  scala.runtime.coverage.Invoker.invoked(5, "coverage-out")
[error]    |                  io.grpc.ServerInterceptors.intercept(service, $1$*)
[error]    |                }
[error]    |              scala.runtime.coverage.Invoker.invoked(4, "coverage-out")
[error]    |              builder.addService($2$)
[error]    |            }
[error]    |          closure($anonfun)
[error]    |        }
[error]    |      scala.runtime.coverage.Invoker.invoked(2, "coverage-out")
[error]    |      services.foldLeft[io.grpc.ServerBuilder[?]](z$1)(op$1)
[error]    |    }
[error]    |  val $4$: io.grpc.BindableService =
[error]    |    {
[error]    |      scala.runtime.coverage.Invoker.invoked(7, "coverage-out")
[error]    |      io.grpc.protobuf.services².ProtoReflectionService.newInstance()
[error]    |    }
[error]    |  scala.runtime.coverage.Invoker.invoked(1, "coverage-out")
[error]    |  $3$.addService²($4$)
[error]    |}.build # -1: TermRef(TypeRef(ThisType(TypeRef(NoPrefix,module class <special-ops>)),type <FromJavaObject>),build) at instrumentCoverage
[error]    |
[error]    |where:    addService  is a method in class ServerBuilder
[error]    |          addService² is a method in class ServerBuilder
[error]    |          services    is a parameter in method createServer
[error]    |          services²   is a package in package io.grpc.protobuf
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
@xuwei-k xuwei-k added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 2, 2024
@Gedochao Gedochao added area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html stat:needs minimization Needs a self contained minimization and removed itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 3, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Oct 3, 2024

Scala CLI example, for convenience:

//> using options -coverage-out:coverage-out
//> using dep io.grpc:grpc-services:1.68.0
import io.grpc.Server
import io.grpc.ServerBuilder
import io.grpc.ServerInterceptors
import io.grpc.ServerServiceDefinition
import io.grpc.protobuf.services.ProtoReflectionService
import io.grpc.util.TransmitStatusRuntimeExceptionInterceptor

object MyServer {
  def createServer(
      port: Int,
      services: List[ServerServiceDefinition]
  ): Server = {
    services
      .foldLeft(ServerBuilder.forPort(port))((builder, service) =>
        builder.addService(
          ServerInterceptors.intercept(
            service,
            TransmitStatusRuntimeExceptionInterceptor.instance()
          )
        )
      )
      .addService(ProtoReflectionService.newInstance())
      .build()
  }
}

BTW it's not actually a compiler crash, we get an actual (if cryptic) error.
Optimally, we'd like it minimized without the io.grpc:grpc-services:1.68.0 dependency.

@xuwei-k
Copy link
Contributor Author

xuwei-k commented Oct 3, 2024

Optimally, we'd like it minimized without the io.grpc:grpc-services:1.68.0 dependency.

Builder.java

package example;

public abstract class Builder<T extends Builder<T>> {
  public abstract String build();
  public abstract T addService(Service service);
}

Service.java

package example;

public class Service{}

A.scala

package example

trait A {
  def x1: Builder[?]
  def x2: Service

  def create: String =
    x1.addService(x2).build()
}
[error] 8 |    x1.addService(x2).build()
[error]   |    ^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |undefined: {
[error]   |  val $1$: example.Builder[?] =
[error]   |    {
[error]   |      scala.runtime.coverage.Invoker.invoked(2, "coverage-out")
[error]   |      this.x1
[error]   |    }
[error]   |  val service$1: example.Service =
[error]   |    {
[error]   |      scala.runtime.coverage.Invoker.invoked(3, "coverage-out")
[error]   |      this.x2
[error]   |    }
[error]   |  scala.runtime.coverage.Invoker.invoked(1, "coverage-out")
[error]   |  $1$.addService(service$1)
[error]   |}.build # -1: TermRef(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any),build) at instrumentCoverage
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

@Gedochao Gedochao added compat:java and removed stat:needs minimization Needs a self contained minimization labels Oct 3, 2024
@odersky
Copy link
Contributor

odersky commented Oct 3, 2024

The error is procduced in Line 170 of ErrorReporting.scala:

    def takesNoParamsMsg(tree: Tree, kind: String): Message =
      if (tree.tpe.widen.exists)
        em"${exprStr(tree)} does not take ${kind}parameters"
      else {
        em"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString} at ${ctx.phase}"
      }

That happens if something that gets applied does not have a valid type (which should not happen). We can try to improve the error message to explain this. But it would be better to figure out who produced this tree without a valid type. Looking at the stacktrace after -Xprompt would help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:coverage Code coverage, see https://dotty.epfl.ch/docs/internals/coverage.html compat:java itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants