scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

mkAttributedQualifier(_1.type, <none>) crash on 2.12.x #12819

Closed wsargent closed 12 months ago

wsargent commented 12 months ago

Reproduction steps

Scala version: 2.12.18 (compiles and works fine in 2.13.x)

Discord chat https://discord.com/channels/632150470000902164/632628489719382036/1125129594803064902

Example test fails https://github.com/tersesystems/echopraxia-plusscala/blob/apply-logger/loggex/src/test/scala/com/tersesystems/echopraxia/plusscala/loggex/ApplyLoggerSpec.scala

Using scala-cli script.sc to minimize it a bit:

//> using scala "2.12.18"

//> using dep "com.tersesystems.echopraxia.plusscala::api:1.2.1"
//> using dep "com.tersesystems.echopraxia:api:2.3.1"
//> using dep "com.tersesystems.echopraxia:logstash:2.3.1"
//> using dep "com.tersesystems.logback:logback-classic:1.2.0"

import com.tersesystems.echopraxia.api.CoreLoggerFactory

import com.tersesystems.echopraxia.plusscala._
import com.tersesystems.echopraxia.plusscala.api._

import com.tersesystems.echopraxia.api.{Field, FieldBuilderResult, Value, Level => JLevel}
import com.tersesystems.echopraxia.api.{CoreLogger, FieldConstants, Utilities}

import scala.compat.java8.FunctionConverters.enrichAsJavaFunction

import java.time.Instant
import java.time.Instant.now

trait DefaultMethodsSupport[FB] {
  def name: String
  def core: CoreLogger
  val fieldBuilder: FB
}

class Loggex[FB](val core: CoreLogger, val fieldBuilder: FB) extends DefaultMethodsSupport[FB] {
  override def name: String = core.getName
  private def createMethod(level: JLevel): LogMethod = new LogMethod(level, this)
  val debug: LogMethod = createMethod(JLevel.DEBUG)
  class LogMethod(val level: JLevel, val support: DefaultMethodsSupport[FB])
}

trait MyFieldBuilder extends FieldBuilder {
  implicit val instantToStringValue: ToValue[Instant] = (t: Instant) => ToValue(t.toString)
  def apply[T: ToValue](value: T): Field = keyValue("derp", ToValue(value))
}
object MyFieldBuilder extends MyFieldBuilder

implicit class EnrichedLogMethod[FB <: MyFieldBuilder.type](lm: Loggex[FB]#LogMethod) {
  import lm.level
  import lm.support._
  def apply[T](message: String, v: T)(implicit ev: lm.support.fieldBuilder.ToValue[T]): Unit = {
    val f: FB => FieldBuilderResult = fb => fb.keyValue("derp", fieldBuilder.ToValue(v))
    core.log(level, message, f.asJava, fieldBuilder)
  }
}

def main() = {
  val coreLogger = CoreLoggerFactory.getLogger("fqcn", "example.Logger")
  val logger = new Loggex(coreLogger, MyFieldBuilder)
  logger.debug("foo {}", now)
}

main()

produces

Error: Unexpected error when compiling project_2e6876faa6-ce3fcbff60: 'assertion failed:
  mkAttributedQualifier(_1.type, <none>)
     while compiling: /home/wsargent/work/mkAttributedQualifier-2.12/.scala-build/project_2e6876faa6-ce3fcbff60/src_generated/main/script.scala
        during phase: globalPhase=typer, enteringPhase=namer
     library version: version 2.12.18
    compiler version: version 2.12.18

Problem

Should not crash.

Might be https://github.com/scala/bug/issues/11259

som-snytt commented 12 months ago

Thanks for the report and related ticket, which was reanimated not long ago. That one still crashes.

I hope the scala-cli people know how great it is to see a scala-cli reproduction. It really lowers the bar or "activation energy" for anyone foolish enough to pursue a fix.

SethTisue commented 12 months ago

When something is fixed in 2.13, we don't keep the ticket open. So I'm closing, but note regardless that:

Despite our best intentions, closing a ticket is sometimes taken as a slap in the face, as we saw on e.g. #11259. I assure you that's not our intention.