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 98e5767
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
8 changes: 6 additions & 2 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 All @@ -4022,7 +4024,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
.showing(i"convert creator $tree -> $result", typr)

def isApplyProxy(tree: Tree) = tree match
case Select(_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
case Select(qual, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
case _ => false

tree match {
Expand All @@ -4040,7 +4042,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
adaptOverloaded(ref)
}
case poly: PolyType if !(ctx.mode is Mode.Type) =>
if isApplyProxy(tree) then newExpr
if isApplyProxy(tree) then
println(i"converting app proxy $tree")
newExpr
else if pt.isInstanceOf[PolyProto] then tree
else
var typeArgs = tree match
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 98e5767

Please sign in to comment.