Skip to content

Crash in summonExpr #7987

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

Closed
biboudis opened this issue Jan 14, 2020 · 9 comments
Closed

Crash in summonExpr #7987

biboudis opened this issue Jan 14, 2020 · 9 comments

Comments

@biboudis
Copy link
Contributor

biboudis commented Jan 14, 2020

minimized code

import scala.quoted._
import scala.deriving._
import scala.quoted.matching._

object Macros {
  inline def m(): Unit = ${ macroImpl() }

  def macroImpl[T]()(given qctx: QuoteContext): Expr[Unit] = {
    summonExpr[Mirror.Of[Some[Int]]]
    '{()}
  }
}
@main def Test() = {
  println(Macros.m())
}
Stack trace
3 |  println(Helper.f(Some(0)))
  |          ^^^^^^^^^^^^^^^^^
  |Exception occurred while executing macro expansion.
  |java.lang.ClassCastException: dotty.tools.dotc.core.Symbols$NoSymbol$ cannot be cast to dotty.tools.dotc.core.Symbols$ClassSymbol
  |     at dotty.tools.dotc.core.Symbols$Symbol.asClass(Symbols.scala:539)
  |     at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2134)
  |     at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2201)
  |     at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2240)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2252)
  |     at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2274)
  |     at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2318)
  |     at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:796)
  |     at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:800)
  |     at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2152)
  |     at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2202)
  |     at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2240)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2252)
  |     at dotty.tools.dotc.typer.Typer.typedNew(Typer.scala:626)
  |     at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2148)
  |     at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2202)
  |     at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2240)
  |     at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2252)
  |     at dotty.tools.dotc.typer.Implicits.anonymousMirror(Implicits.scala:892)
  |     at dotty.tools.dotc.typer.Implicits.mirrorFor$2(Implicits.scala:980)
  |     at dotty.tools.dotc.typer.Implicits.synthesizedProductMirror$$anonfun$1$$anonfun$1(Implicits.scala:991)
  |     at dotty.tools.dotc.typer.Implicits.synthesizedMirror$$anonfun$1$$anonfun$1(Implicits.scala:1080)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1123)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$2$$anonfun$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.ast.Trees$Tree.orElse(Trees.scala:185)
  |     at dotty.tools.dotc.typer.Implicits.trySpecialCases$1(Implicits.scala:1125)
  |     at dotty.tools.dotc.typer.Implicits.inferImplicitArg(Implicits.scala:1130)
  |     at dotty.tools.dotc.typer.Typer.inferImplicitArg(Typer.scala:83)
  |     at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.searchImplicit(ReflectionCompilerInterface.scala:1912)
  |     at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.searchImplicit(ReflectionCompilerInterface.scala:1911)
  |     at scala.tasty.reflect.ImplicitsOps.searchImplicit(ImplicitsOps.scala:6)
  |     at scala.tasty.Reflection.searchImplicit(Reflection.scala:6)
  |     at scala.quoted.matching.package$.summonExpr(package.scala:15)
  |     at Helper$.macroImpl(Macro_1.scala:26)
  |
  | This location contains code that was inlined from Test_2.scala:3

inlined at Test_2.scala:3:

This resulted after further investigating this #7974

@biboudis
Copy link
Contributor Author

biboudis commented Jan 15, 2020

It is related to the fact that Some is Scala2 and it gets through that mechanism of anonymousMirror and blows up when the following is going to be typed:

final class $anon extends Object {
  type MirroredMonoType = Some[Int]
}

but its symbol is None

@milessabin
Copy link
Contributor

How come Some's symbol is None?

@biboudis
Copy link
Contributor Author

So, the insight that the stacktrace gives is that after the anonymousMirror call we see instances of ReTyper. ReTyper has different assumptions with regard to completed symbols than Typer. We've tried to setTyper manually but ReTyper still is used. It needs a bit more investigation.

@milessabin
Copy link
Contributor

Is this actually related to Mirror? Or would any type with a comparable refinement trip the same bug?

@biboudis
Copy link
Contributor Author

biboudis commented Jan 17, 2020

Did you have in mind something like that?

given (Option[Int] { type TT }) = Some(2).asInstanceOf[Option[Int] { type TT = Float }]
summonExpr[Option[Int] { type TT = Float }]

^^ compiles ok btw

@milessabin
Copy link
Contributor

Yeah, something like that.

compiles ok btw

In the body of a macro?

@biboudis
Copy link
Contributor Author

Yeap

biboudis added a commit to dotty-staging/dotty that referenced this issue Jan 20, 2020
@nicolasstucki
Copy link
Contributor

We were just using the wrong kind of typer.

@biboudis
Copy link
Contributor Author

Ah. During macro expansion. The Type Assigner. Nice. 👍👍👍

nicolasstucki added a commit that referenced this issue Jan 29, 2020
Fix #7987: Use normal typer when expanding a macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants