diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 4048e820d281..03bba910e348 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -67,7 +67,6 @@ object Parsers { this == Given || this == ExtensionFollow def acceptsVariance = this == Class || this == CaseClass || this == Type - end ParamOwner enum ParseKind: @@ -3283,7 +3282,7 @@ object Parsers { ok def typeParam(): TypeDef = { - val isAbstractOwner = paramOwner == ParamOwner.Type || paramOwner == ParamOwner.TypeParam + val isAbstractOwner = (paramOwner == ParamOwner.Type || paramOwner == ParamOwner.TypeParam) val start = in.offset var mods = annotsAsMods() | Param if paramOwner == ParamOwner.Class || paramOwner == ParamOwner.CaseClass then @@ -3304,7 +3303,13 @@ object Parsers { } else ident().toTypeName val hkparams = typeParamClauseOpt(ParamOwner.Type) - val bounds = if (isAbstractOwner) typeBounds() else typeParamBounds(name) + // val bounds = if (isAbstractOwner) typeBounds() else typeParamBounds(name) + val bounds = typeParamBounds(name) match + case bounds: TypeBoundsTree => bounds + case bounds: ContextBounds if !isAbstractOwner => bounds + case ContextBounds(bounds, cxBounds) => + for cbound <- cxBounds do report.error(IllegalContextBounds(), cbound.srcPos) + bounds TypeDef(name, lambdaAbstract(hkparams, bounds)).withMods(mods) } } diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index d3ac238fbc5c..896e00a46053 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -225,6 +225,9 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case FormatInterpolationErrorID // errorNumber: 209 case ValueClassCannotExtendAliasOfAnyValID // errorNumber: 210 case MatchIsNotPartialFunctionID // errorNumber: 211 + case OnlyFullyDependentAppliedConstructorTypeID // errorNumber: 212 + case PointlessAppliedConstructorTypeID // errorNumber: 213 + case IllegalContextBoundsID // errorNumber: 214 def errorNumber = ordinal - 1 diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 2fe847d6aff1..71ab24cf4941 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -3255,3 +3255,11 @@ class MatchIsNotPartialFunction(using Context) extends SyntaxMsg(MatchIsNotParti | |Efficient operations will use `applyOrElse` to avoid computing the match twice, |but the `apply` body would be executed "per element" in the example.""" + +final class IllegalContextBounds(using Context) extends SyntaxMsg(IllegalContextBoundsID): + override protected def msg(using Context): String = + i"Context bounds are not allowed in this position" + + override protected def explain(using Context): String = "" + +end IllegalContextBounds diff --git a/tests/neg/i22552.check b/tests/neg/i22552.check index 910c8ad44c11..f6713b480699 100644 --- a/tests/neg/i22552.check +++ b/tests/neg/i22552.check @@ -1,12 +1,12 @@ --- [E040] Syntax Error: tests/neg/i22552.scala:3:10 -------------------------------------------------------------------- +-- [E214] Syntax Error: tests/neg/i22552.scala:3:10 -------------------------------------------------------------------- 3 | type A[X: TC] // error - | ^ - | ']' expected, but ':' found --- [E040] Syntax Error: tests/neg/i22552.scala:4:13 -------------------------------------------------------------------- + | ^^^^ + | Context bounds are not allowed in this position +-- [E214] Syntax Error: tests/neg/i22552.scala:4:13 -------------------------------------------------------------------- 4 | type C = [X: TC] =>> List[X] // error - | ^ - | ']' expected, but ':' found --- [E040] Syntax Error: tests/neg/i22552.scala:5:13 -------------------------------------------------------------------- + | ^^^^ + | Context bounds are not allowed in this position +-- [E214] Syntax Error: tests/neg/i22552.scala:5:13 -------------------------------------------------------------------- 5 | type D = [X: TC] => () => List[X] // error - | ^ - | ']' expected, but ':' found + | ^^^^ + | Context bounds are not allowed in this position diff --git a/tests/neg/i22660.check b/tests/neg/i22660.check new file mode 100644 index 000000000000..22c8b68654e3 --- /dev/null +++ b/tests/neg/i22660.check @@ -0,0 +1,4 @@ +-- [E214] Syntax Error: tests/neg/i22660.scala:2:10 -------------------------------------------------------------------- +2 |type Foo[T: Equatable] // error + | ^^^^^^^^^^^ + | Context bounds are not allowed in this position diff --git a/tests/neg/i22660.scala b/tests/neg/i22660.scala new file mode 100644 index 000000000000..650ceac4f48c --- /dev/null +++ b/tests/neg/i22660.scala @@ -0,0 +1,2 @@ +trait Equatable[T] +type Foo[T: Equatable] // error