@@ -1819,8 +1819,9 @@ object Parsers {
1819
1819
val start = in.offset
1820
1820
val tparams = typeParamClause(ParamOwner .Type )
1821
1821
if in.token == TLARROW then
1822
+ // Filter illegal context bounds and report syntax error
1822
1823
atSpan(start, in.skipToken()):
1823
- LambdaTypeTree (tparams, toplevelTyp())
1824
+ LambdaTypeTree (tparams.mapConserve(stripContextBounds( " type lambdas " )) , toplevelTyp())
1824
1825
else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
1825
1826
val arrowOffset = in.skipToken()
1826
1827
val body = toplevelTyp(nestedIntoOK(in.token))
@@ -1836,6 +1837,13 @@ object Parsers {
1836
1837
typeRest(infixType(inContextBound))
1837
1838
end typ
1838
1839
1840
+ /** Removes context bounds from TypeDefs and returns a syntax error. */
1841
+ private def stripContextBounds (in : String )(tparam : TypeDef ) = tparam match
1842
+ case TypeDef (name, rhs : ContextBounds ) =>
1843
+ syntaxError(em " context bounds are not allowed in $in" , rhs.span)
1844
+ TypeDef (name, rhs.bounds)
1845
+ case other => other
1846
+
1839
1847
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
1840
1848
val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
1841
1849
// We remove the variance marker from the name without passing along the specified variance at all
@@ -3498,7 +3506,7 @@ object Parsers {
3498
3506
*
3499
3507
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3500
3508
* HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3501
- * (id | ‘_’) [HkTypePamClause ] TypeBounds
3509
+ * (id | ‘_’) [HkTypeParamClause ] TypeBounds
3502
3510
*/
3503
3511
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3504
3512
0 commit comments