From 3ee5b29d010af0f15769dc19892c0b72de805490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Bra=C4=8Devac?= Date: Thu, 17 Apr 2025 16:23:44 +0200 Subject: [PATCH] Disallow context function types as value-class parameters --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 ++ tests/neg/i22752.scala | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 tests/neg/i22752.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 0c5697a26fce..2eec6579492b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -778,6 +778,8 @@ object Checking { } clParamAccessors match { case param :: params => + if (defn.isContextFunctionType(param.info)) + report.error("value classes are not allowed for context function types", param.srcPos) if (param.is(Mutable)) report.error(ValueClassParameterMayNotBeAVar(clazz, param), param.srcPos) if (param.info.isInstanceOf[ExprType]) diff --git a/tests/neg/i22752.scala b/tests/neg/i22752.scala new file mode 100644 index 000000000000..5c93b3ccbd68 --- /dev/null +++ b/tests/neg/i22752.scala @@ -0,0 +1,4 @@ +class Inner(body: Int ?=> Int) extends AnyVal: // error + def rescue: Int ?=> Int = ??? + +class Inner2(body: Int => Int) extends AnyVal // ok