From 6b1eda35a358f49f2d367177fea6a361acef5ea6 Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 25 Sep 2022 12:14:02 +0200 Subject: [PATCH 1/3] Test case --- tests/neg/i16095.scala | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/neg/i16095.scala diff --git a/tests/neg/i16095.scala b/tests/neg/i16095.scala new file mode 100644 index 000000000000..b1547bae6b68 --- /dev/null +++ b/tests/neg/i16095.scala @@ -0,0 +1,30 @@ +package x + +import scala.annotation.* +import scala.concurrent.* + +@capability +class CpsTransform[F[_]] { + def await[T](ft: F[T]): { this } T = ??? +} + +inline def cpsAsync[F[_]] = + Test.InfernAsyncArg +object Test { + + class InfernAsyncArg[F[_]] { + def apply[A](expr: CpsTransform[F] ?=> A): F[A] = ??? + } + + def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): { cps } Int = + a + cps.await(b) + + 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)) + +} \ No newline at end of file From 65544545034d66f88f10464e1de6b8be1deb3f54 Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 25 Sep 2022 21:32:58 +0200 Subject: [PATCH 2/3] Avoid crash where creator proxies are referenced indirectly Fixes #16095 --- .../src/dotty/tools/dotc/typer/Typer.scala | 2 ++ tests/neg/i16095.scala | 24 ++++--------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 17271618cf09..b8e8bd68c8f8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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( diff --git a/tests/neg/i16095.scala b/tests/neg/i16095.scala index b1547bae6b68..1d8085cec53f 100644 --- a/tests/neg/i16095.scala +++ b/tests/neg/i16095.scala @@ -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 } \ No newline at end of file From 873338e01f101ab599505281e389a671922aeb0e Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 26 Sep 2022 12:08:28 +0200 Subject: [PATCH 3/3] Update compiler/src/dotty/tools/dotc/typer/Typer.scala Co-authored-by: Jan Chyb <48855024+jchyb@users.noreply.github.com> --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index b8e8bd68c8f8..6a1e6e0b671f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -4014,7 +4014,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer 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") + errorTree(tree, em"cannot convert from $tree to an instance creation expression") val tycon = tree.tpe.widen.finalResultType.underlyingClassRef(refinementOK = false) typed( untpd.Select(