Skip to content

CyclicReference when showing a generic type from a macro #8858

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

Minimized code

macro.scala

import scala.quoted._

inline def mcr(inline x: Any): Any = ${ mcrImpl('x) }
def mcrImpl(expr: Expr[Any])(using ctx: QuoteContext): Expr[Any] =
  import ctx.tasty._
  expr.unseal match
    case Inlined(_, _, id1) =>
      println(id1.tpe.widen.show)
  '{()}

test.scala

trait Foo[A]
def check[T](x: Foo[T]) = mcr(x)

launch.iss (to reproduce with Dotty Issue Workspace)

$ rm -rv $here/*.tasty $here/*.class || true

dotty-bootstrapped/dotc -d $here
  $here/macro.scala

dotty-bootstrapped/dotc -d $here
  -classpath $here
  $here/test.scala

Output (click arrow to expand)

-- Error: /Users/kmetiuk/Projects/scala3/playground/utest-issue-1/test.scala:2:29
2 |def check[T](x: Foo[T]) = mcr(x)
  |                          ^^^^^^
  |Exception occurred while executing macro expansion.
  |dotty.tools.dotc.core.CyclicReference:
  |	at dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:156)
  |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:257)
  |	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:186)
  |	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:188)
  |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:446)
  |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.flags(SymDenotations.scala:158)
  |	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_flags(ReflectionCompilerInterface.scala:1669)
  |	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_flags(ReflectionCompilerInterface.scala:1669)
  |	at scala.tasty.Reflection$SymbolOps$.flags(Reflection.scala:2129)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printType(SourceCodePrinter.scala:1087)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printTypeOrBound(SourceCodePrinter.scala:1067)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printSeparated$9(SourceCodePrinter.scala:722)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printTypesOrBounds(SourceCodePrinter.scala:728)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printType$$anonfun$1(SourceCodePrinter.scala:1131)
  |	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.inSquare(SourceCodePrinter.scala:81)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printType(SourceCodePrinter.scala:1131)
  |	at scala.tasty.reflect.SourceCodePrinter$Buffer.printTypeOrBound(SourceCodePrinter.scala:1067)
  |	at scala.tasty.reflect.SourceCodePrinter.showTypeOrBounds(SourceCodePrinter.scala:16)
  |	at scala.tasty.Reflection$TypeOrBoundsOps$.showWith(Reflection.scala:1597)
  |	at scala.tasty.Reflection$TypeOrBoundsOps$.show(Reflection.scala:1593)
  |	at macro$package$.mcrImpl(macro.scala:8)
  |
  | This location contains code that was inlined from test.scala:2
1 error found

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions