@@ -1798,22 +1798,9 @@ object Parsers {
17981798 val start = in.offset
17991799 val tparams = typeParamClause(ParamOwner .Type )
18001800 if in.token == TLARROW then
1801- val hasContextBounds = tparams.exists(_.rhs match {
1802- case x : ContextBounds => true
1803- case _ => false
1804- })
1805- if hasContextBounds then
1806- // Filter illegal context bounds and report syntax error
1807- atSpan(start, in.skipToken()):
1808- LambdaTypeTree (tparams.map {
1809- case TypeDef (name, rhs : ContextBounds ) =>
1810- syntaxError(em " context bounds are not allowed in type lambdas " , rhs.span)
1811- TypeDef (name, TypeBoundsTree (EmptyTree , EmptyTree ))
1812- case other => other
1813- }, toplevelTyp())
1814- else
1815- atSpan(start, in.skipToken()):
1816- LambdaTypeTree (tparams, toplevelTyp())
1801+ // Filter illegal context bounds and report syntax error
1802+ atSpan(start, in.skipToken()):
1803+ LambdaTypeTree (tparams.mapConserve(stripContextBounds(" type lambdas" )), toplevelTyp())
18171804 else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
18181805 val arrowOffset = in.skipToken()
18191806 val body = toplevelTyp(nestedIntoOK(in.token))
@@ -1829,6 +1816,13 @@ object Parsers {
18291816 typeRest(infixType(inContextBound))
18301817 end typ
18311818
1819+ /** Removes context bounds from TypeDefs and returns a syntax error. */
1820+ private def stripContextBounds (in : String )(tparam : TypeDef ) = tparam match
1821+ case TypeDef (name, rhs : ContextBounds ) =>
1822+ syntaxError(em " context bounds are not allowed in $in" , rhs.span)
1823+ TypeDef (name, rhs.bounds)
1824+ case other => other
1825+
18321826 private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
18331827 val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
18341828 // We remove the variance marker from the name without passing along the specified variance at all
0 commit comments