Skip to content

Commit 98e5767

Browse files
committed
Avoid crash where creator proxies are referenced indirectly
Fixes #16095
1 parent 6b1eda3 commit 98e5767

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,6 +4013,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40134013
cpy.Select(qual)(pre, name.toTypeName)
40144014
case qual: This if qual.symbol.is(ModuleClass) =>
40154015
cpy.Ident(qual)(qual.symbol.name.sourceModuleName.toTypeName)
4016+
case _ =>
4017+
errorTree(tree, em"cannot convert to $tree to an instance creation expression")
40164018
val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false)
40174019
typed(
40184020
untpd.Select(
@@ -4022,7 +4024,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40224024
.showing(i"convert creator $tree -> $result", typr)
40234025

40244026
def isApplyProxy(tree: Tree) = tree match
4025-
case Select(_, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
4027+
case Select(qual, nme.apply) => tree.symbol.isAllOf(ApplyProxyFlags)
40264028
case _ => false
40274029

40284030
tree match {
@@ -4040,7 +4042,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
40404042
adaptOverloaded(ref)
40414043
}
40424044
case poly: PolyType if !(ctx.mode is Mode.Type) =>
4043-
if isApplyProxy(tree) then newExpr
4045+
if isApplyProxy(tree) then
4046+
println(i"converting app proxy $tree")
4047+
newExpr
40444048
else if pt.isInstanceOf[PolyProto] then tree
40454049
else
40464050
var typeArgs = tree match

tests/neg/i16095.scala

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
package x
22

3-
import scala.annotation.*
43
import scala.concurrent.*
54

6-
@capability
7-
class CpsTransform[F[_]] {
8-
def await[T](ft: F[T]): { this } T = ???
9-
}
10-
11-
inline def cpsAsync[F[_]] =
5+
def cpsAsync[F[_]] =
126
Test.InfernAsyncArg
13-
object Test {
147

8+
object Test {
159
class InfernAsyncArg[F[_]] {
16-
def apply[A](expr: CpsTransform[F] ?=> A): F[A] = ???
10+
def apply[A](): F[A] = ???
1711
}
18-
19-
def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): { cps } Int =
20-
a + cps.await(b)
12+
object InfernAsyncArg
2113

2214
def testExample1Future(): Unit =
23-
val fr = cpsAsync[Future] {
24-
val y = asyncPlus(1,Future successful 2)
25-
y+1
26-
}
27-
val r = Await.result(fr)
28-
assert(r == Success(3))
29-
15+
val fr = cpsAsync[Future]() // error
3016
}

0 commit comments

Comments
 (0)