From 5c6ecefa08bc573944998f6328e764607d99f92f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 6 Jan 2021 19:26:32 +0100 Subject: [PATCH] Disallow type lambdas as F-bounds Given parameter ``` C <: [Y] => ... C[T] ... ``` change error message for `C[T]` to explain that type lambdas are not supported as F-bounds --- .../src/dotty/tools/dotc/reporting/messages.scala | 6 +++++- tests/neg/i8752.check | 11 +++++++++++ tests/neg/i8752.scala | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i8752.check create mode 100644 tests/neg/i8752.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 2c3689749334..2431fc969675 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -1386,7 +1386,11 @@ import transform.SymUtils._ class TypeDoesNotTakeParameters(tpe: Type, params: List[Trees.Tree[Trees.Untyped]])(using Context) extends TypeMsg(TypeDoesNotTakeParametersID) { - def msg = em"$tpe does not take type parameters" + private def fboundsAddendum = + if tpe.typeSymbol.isAllOf(Provisional | TypeParam) then + "\n(Note that F-bounds of type parameters may not be type lambdas)" + else "" + def msg = em"$tpe does not take type parameters$fboundsAddendum" def explain = val ps = if (params.size == 1) s"a type parameter ${params.head}" diff --git a/tests/neg/i8752.check b/tests/neg/i8752.check new file mode 100644 index 000000000000..6d1cf47aa2fd --- /dev/null +++ b/tests/neg/i8752.check @@ -0,0 +1,11 @@ +-- [E053] Type Error: tests/neg/i8752.scala:3:41 ----------------------------------------------------------------------- +3 |trait Arround1[C <:[X]=>>IterableOps[X,C,C[X]] ] // error // error + | ^^^^ + | C does not take type parameters + | (Note that F-bounds of type parameters may not be type lambdas) + +longer explanation available when compiling with `-explain` +-- Error: tests/neg/i8752.scala:3:39 ----------------------------------------------------------------------------------- +3 |trait Arround1[C <:[X]=>>IterableOps[X,C,C[X]] ] // error // error + | ^ + | Type argument C does not have the same kind as its bound [_] diff --git a/tests/neg/i8752.scala b/tests/neg/i8752.scala new file mode 100644 index 000000000000..e28f3f069675 --- /dev/null +++ b/tests/neg/i8752.scala @@ -0,0 +1,3 @@ +import scala.collection.IterableOps + +trait Arround1[C <:[X]=>>IterableOps[X,C,C[X]] ] // error // error