Skip to content

Commit

Permalink
Avoid crash where creator proxies are referenced indirectly
Browse files Browse the repository at this point in the history
Fixes #16095
  • Loading branch information
odersky committed Sep 25, 2022
1 parent 6b1eda3 commit 6554454
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4013,6 +4013,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
cpy.Select(qual)(pre, name.toTypeName)
case qual: This if qual.symbol.is(ModuleClass) =>
cpy.Ident(qual)(qual.symbol.name.sourceModuleName.toTypeName)
case _ =>
errorTree(tree, em"cannot convert to $tree to an instance creation expression")
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
typed(
untpd.Select(
Expand Down
24 changes: 5 additions & 19 deletions tests/neg/i16095.scala
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package x

import scala.annotation.*
import scala.concurrent.*

@capability
class CpsTransform[F[_]] {
def await[T](ft: F[T]): { this } T = ???
}

inline def cpsAsync[F[_]] =
def cpsAsync[F[_]] =
Test.InfernAsyncArg
object Test {

object Test {
class InfernAsyncArg[F[_]] {
def apply[A](expr: CpsTransform[F] ?=> A): F[A] = ???
def apply[A](): F[A] = ???
}

def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): { cps } Int =
a + cps.await(b)
object InfernAsyncArg

def testExample1Future(): Unit =
val fr = cpsAsync[Future] {
val y = asyncPlus(1,Future successful 2)
y+1
}
val r = Await.result(fr)
assert(r == Success(3))

val fr = cpsAsync[Future]() // error
}

0 comments on commit 6554454

Please sign in to comment.