Skip to content

Commit

Permalink
Detect cyclic dependencies when loading modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Jul 28, 2021
1 parent 23be42c commit 0ba627b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
18 changes: 12 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,18 @@ object Splicer {

private def interpretedStaticMethodCall(moduleClass: Symbol, fn: Symbol)(implicit env: Env): List[Object] => Object = {
val (inst, clazz) =
if (moduleClass.name.startsWith(str.REPL_SESSION_LINE))
(null, loadReplLineClass(moduleClass))
else {
val inst = loadModule(moduleClass)
(inst, inst.getClass)
}
try
if (moduleClass.name.startsWith(str.REPL_SESSION_LINE))
(null, loadReplLineClass(moduleClass))
else {
val inst = loadModule(moduleClass)
(inst, inst.getClass)
}
catch
case MissingClassDefinedInCurrentRun(sym) if ctx.compilationUnit.isSuspendable =>
if (ctx.settings.XprintSuspension.value)
report.echo(i"suspension triggered by a dependency on $sym", pos)
ctx.compilationUnit.suspend() // this throws a SuspendException

val name = fn.name.asTermName
val method = getMethod(clazz, name, paramsSig(fn))
Expand Down
21 changes: 21 additions & 0 deletions tests/neg-macros/i12788/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import scala.quoted.*

class InlinedInt[T <: Int]

object DFType:
trait Width[T]:
type Out <: Int
transparent inline given [T]: Width[T] = ${ getWidthMacro[T] }
def getWidthMacro[T](using Quotes, Type[T]): Expr[Width[T]] =
'{
new Width[T] {
type Out = 1
}
}

trait DFBits[W <: Int]
object DFBits extends DFBitsCompanion

trait DFToken[T]
extension [T](token: DFToken[T])(using w: DFType.Width[T])
def width: InlinedInt[w.Out] = ???
4 changes: 4 additions & 0 deletions tests/neg-macros/i12788/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// nopos-error
trait DFBitsCompanion:
type Token[W <: Int] = DFToken[DFType.DFBits[W]]
extension [LW <: Int](lhs: DFType.DFBits.Token[LW]) def foo: Unit = lhs.width

0 comments on commit 0ba627b

Please sign in to comment.