@@ -1798,22 +1798,9 @@ object Parsers {
1798
1798
val start = in.offset
1799
1799
val tparams = typeParamClause(ParamOwner .Type )
1800
1800
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())
1817
1804
else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
1818
1805
val arrowOffset = in.skipToken()
1819
1806
val body = toplevelTyp(nestedIntoOK(in.token))
@@ -1829,6 +1816,13 @@ object Parsers {
1829
1816
typeRest(infixType(inContextBound))
1830
1817
end typ
1831
1818
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
+
1832
1826
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
1833
1827
val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
1834
1828
// We remove the variance marker from the name without passing along the specified variance at all
0 commit comments