File tree 6 files changed +26
-9
lines changed
compiler/src/dotty/tools/dotc
6 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -68,8 +68,8 @@ object Parsers {
68
68
this == Given || this == ExtensionFollow
69
69
def acceptsVariance =
70
70
this == Class || this == CaseClass || this == Hk
71
- def acceptsCtxBounds =
72
- ! (this == Type || this == Hk )
71
+ def acceptsCtxBounds ( using Context ) =
72
+ ! (this == Type || this == Hk ) || (sourceVersion.enablesNewGivens && this == Type )
73
73
def acceptsWildcard =
74
74
this == Type || this == Hk
75
75
@@ -3549,10 +3549,12 @@ 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()
3552
+ val bounds = typeAndCtxBounds(name) match
3553
+ case bounds : TypeBoundsTree => bounds
3554
+ case bounds : ContextBounds if paramOwner.acceptsCtxBounds => bounds
3555
+ case ContextBounds (bounds, cxBounds) =>
3556
+ for cbound <- cxBounds do report.error(IllegalContextBounds (), cbound.srcPos)
3557
+ bounds
3556
3558
val res = TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3557
3559
if isCap then
3558
3560
res.pushAttachment(CaptureVar , ())
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 @@ -3516,3 +3516,11 @@ final class OnlyFullyDependentAppliedConstructorType()(using Context)
3516
3516
i " Applied constructor type can only be used with classes where all parameters in the first parameter list are tracked "
3517
3517
3518
3518
override protected def explain (using Context ): String = " "
3519
+
3520
+ final class IllegalContextBounds (using Context ) extends SyntaxMsg (IllegalContextBoundsID ):
3521
+ override protected def msg (using Context ): String =
3522
+ i " Context bounds are not allowed in this position "
3523
+
3524
+ override protected def explain (using Context ): String = " "
3525
+
3526
+ 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:14 --------------------------------------------------------------------
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:21 --------------------------------------------------------------------
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