@@ -1677,8 +1677,9 @@ object Parsers {
1677
1677
val start = in.offset
1678
1678
val tparams = typeParamClause(ParamOwner .TypeParam )
1679
1679
if in.token == TLARROW then
1680
+ // Filter illegal context bounds and report syntax error
1680
1681
atSpan(start, in.skipToken()):
1681
- LambdaTypeTree (tparams, toplevelTyp())
1682
+ LambdaTypeTree (tparams.mapConserve(stripContextBounds( " type lambdas " )) , toplevelTyp())
1682
1683
else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
1683
1684
val arrowOffset = in.skipToken()
1684
1685
val body = toplevelTyp()
@@ -1699,6 +1700,13 @@ object Parsers {
1699
1700
typeRest(infixType())
1700
1701
end typ
1701
1702
1703
+ /** Removes context bounds from TypeDefs and returns a syntax error. */
1704
+ private def stripContextBounds (in : String )(tparam : TypeDef ) = tparam match
1705
+ case TypeDef (name, rhs : ContextBounds ) =>
1706
+ syntaxError(em " context bounds are not allowed in $in" , rhs.span)
1707
+ TypeDef (name, rhs.bounds)
1708
+ case other => other
1709
+
1702
1710
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
1703
1711
val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
1704
1712
// We remove the variance marker from the name without passing along the specified variance at all
@@ -3267,7 +3275,8 @@ object Parsers {
3267
3275
* TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3268
3276
*
3269
3277
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3270
- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3278
+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3279
+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
3271
3280
*/
3272
3281
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3273
3282
0 commit comments