@@ -1677,8 +1677,9 @@ object Parsers {
16771677 val start = in.offset
16781678 val tparams = typeParamClause(ParamOwner .TypeParam )
16791679 if in.token == TLARROW then
1680+ // Filter illegal context bounds and report syntax error
16801681 atSpan(start, in.skipToken()):
1681- LambdaTypeTree (tparams, toplevelTyp())
1682+ LambdaTypeTree (tparams.mapConserve(stripContextBounds( " type lambdas " )) , toplevelTyp())
16821683 else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
16831684 val arrowOffset = in.skipToken()
16841685 val body = toplevelTyp()
@@ -1699,6 +1700,13 @@ object Parsers {
16991700 typeRest(infixType())
17001701 end typ
17011702
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+
17021710 private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
17031711 val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
17041712 // We remove the variance marker from the name without passing along the specified variance at all
@@ -3267,7 +3275,8 @@ object Parsers {
32673275 * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
32683276 *
32693277 * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3270- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3278+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3279+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
32713280 */
32723281 def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
32733282
0 commit comments