File tree 6 files changed +29
-8
lines changed
compiler/src/dotty/tools/dotc
6 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -3549,11 +3549,17 @@ object Parsers {
3549
3549
else ident().toTypeName
3550
3550
val isCap = gobbleHat()
3551
3551
val hkparams = typeParamClauseOpt(ParamOwner .Hk )
3552
- val bounds =
3553
- if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name)
3554
- else if sourceVersion.enablesNewGivens && paramOwner == ParamOwner .Type then typeAndCtxBounds(name)
3555
- else typeBounds()
3556
- val res = TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3552
+ val bounds = typeAndCtxBounds(name)
3553
+ val res = bounds match
3554
+ case bounds : ContextBounds if paramOwner.acceptsCtxBounds =>
3555
+ TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3556
+ case bounds : ContextBounds if sourceVersion.enablesNewGivens && paramOwner == ParamOwner .Type =>
3557
+ TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3558
+ case ContextBounds (bounds, _) =>
3559
+ report.error(IllegalContextBounds (), bounds.srcPos)
3560
+ TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3561
+ case bounds : TypeBoundsTree =>
3562
+ TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3557
3563
if isCap then
3558
3564
res.pushAttachment(CaptureVar , ())
3559
3565
// putting the attachment here as well makes post-processing in the typer easier
Original file line number Diff line number Diff line change @@ -227,6 +227,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
227
227
case MatchIsNotPartialFunctionID // errorNumber: 211
228
228
case OnlyFullyDependentAppliedConstructorTypeID // errorNumber: 212
229
229
case PointlessAppliedConstructorTypeID // errorNumber: 213
230
+ case IllegalContextBoundsID // errorNumber: 214
230
231
231
232
def errorNumber = ordinal - 1
232
233
Original file line number Diff line number Diff line change @@ -3510,3 +3510,11 @@ final class OnlyFullyDependentAppliedConstructorType()(using Context)
3510
3510
i " Applied constructor type can only be used with classes where all parameters in the first parameter list are tracked "
3511
3511
3512
3512
override protected def explain (using Context ): String = " "
3513
+
3514
+ final class IllegalContextBounds (using Context ) extends SyntaxMsg (IllegalContextBoundsID ):
3515
+ override protected def msg (using Context ): String =
3516
+ i " Context bounds are not allowed in this position "
3517
+
3518
+ override protected def explain (using Context ): String = " "
3519
+
3520
+ end IllegalContextBounds
Original file line number Diff line number Diff line change 1
- -- [E040 ] Syntax Error: tests/neg/i22552.scala:3:10 --------------------------------------------------------------------
1
+ -- [E214 ] Syntax Error: tests/neg/i22552.scala:3:12 --------------------------------------------------------------------
2
2
3 | type A[X: TC] // error
3
- | ^
4
- | ']' expected, but ':' found
3
+ | ^
4
+ | Context bounds are not allowed in this position
5
5
-- Error: tests/neg/i22552.scala:4:15 ----------------------------------------------------------------------------------
6
6
4 | type C = [X: TC] =>> List[X] // error
7
7
| ^^
Original file line number Diff line number Diff line change
1
+ -- [E214] Syntax Error: tests/neg/i22660.scala:2:12 --------------------------------------------------------------------
2
+ 2 |type Foo[T: Equatable] // error
3
+ | ^
4
+ | Context bounds are not allowed in this position
Original file line number Diff line number Diff line change
1
+ trait Equatable [T ]
2
+ type Foo [T : Equatable ] // error
You can’t perform that action at this time.
0 commit comments