Skip to content

ClassCastException while executing macro expansion on Scala3 #836

@hiroshi-cl

Description

@hiroshi-cl

Play JSON Version (2.5.x / etc)

2.10.0-RC7

API (Scala / Java / Neither / Both)

Scala 3 (3.2.1)

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Mac OS 12.6.2

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

Library Dependencies

Nothing

Expected Behavior

Possible to compile this code on Scala 3.

import play.api.libs.json.Format
import play.api.libs.json.Json

case class JsonModel(rawString: String) extends AnyVal

object JsonModel {
  implicit val format: Format[JsonModel] = Json.valueFormat[JsonModel]
}

import play.api.libs.json.JsSuccess
import play.api.libs.json.Json
import play.api.libs.json.Reads

class Spec {

  case class Test(underlying: Option[JsonModel])

  object Test {
    implicit val reads: Reads[Test] = Json.reads[Test]
  }
}

Actual Behavior

ClassCastException on Scala 3. (No problem on Scala 2)

[error] 19 |    implicit val reads: Reads[Test] = Json.reads[Test]
[error]    |                                      ^^^^^^^^^^^^^^^^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.ClassCastException: class dotty.tools.dotc.ast.Trees$This cannot be cast to class dotty.tools.dotc.ast.Trees$RefTree (dotty.tools.dotc.ast.Trees$This and dotty.tools.dotc.ast.Trees$RefTree are in unnamed module of loader sbt.internal.classpath.ClassLoaderCache$Key$CachedClassLoader @210722d7)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl.scala$quoted$runtime$impl$QuotesImpl$reflect$Ref$$$_$apply$$anonfun$6(QuotesImpl.scala:436)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$withDefaultPos(QuotesImpl.scala:2906)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:436)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:434)
[error]    |    at play.api.libs.json.JsMacroImpl$ReadsHelper.productReads(JsMacroImpl.scala:322)
[error]    |    at play.api.libs.json.JsMacroImpl$ReadsHelper.productReads$(JsMacroImpl.scala:198)
[error]    |    at play.api.libs.json.JsMacroImpl$$anon$1.productReads(JsMacroImpl.scala:127)
[error]    |    at play.api.libs.json.JsMacroImpl$.readsExpr(JsMacroImpl.scala:168)
[error]    |    at play.api.libs.json.JsMacroImpl$.$anonfun$1(JsMacroImpl.scala:105)
[error]    |    at play.api.libs.json.JsMacroImpl$.$anonfun$adapted$1(JsMacroImpl.scala:105)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:109)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1446)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformBlock(Trees.scala:1505)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1478)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507)
[error]    |    at scala.collection.immutable.List.mapConserve(List.scala:472)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1503)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformBlock(Trees.scala:1505)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformBlock(Trees.scala:1505)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507)
[error]    |    at scala.collection.immutable.List.mapConserve(List.scala:472)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1412)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformBlock(Trees.scala:1505)
[error]    |    at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:134)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:151)
[error]    |    at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:87)
[error]    |    at scala.quoted.runtime.impl.QuotesImpl.unpickleExprV2(QuotesImpl.scala:3044)
[error]    |    at play.api.libs.json.JsMacroImpl$.configuredReads(JsMacroImpl.scala:105)
[error]    |    at play.api.libs.json.JsMacroImpl$.reads$$anonfun$1(JsMacroImpl.scala:51)
[error]    |    at play.api.libs.json.JsMacroImpl$.withSummonedConfig(JsMacroImpl.scala:79)
[error]    |    at play.api.libs.json.JsMacroImpl$.reads(JsMacroImpl.scala:51)
[error]    |
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from JsMacros.scala:28
[error]     ----------------------------------------------------------------------------
[error] one error found

Reproducible Test Case

above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions