@@ -1819,8 +1819,9 @@ object Parsers {
18191819 val start = in.offset
18201820 val tparams = typeParamClause(ParamOwner .Type )
18211821 if in.token == TLARROW then
1822+ // Filter illegal context bounds and report syntax error
18221823 atSpan(start, in.skipToken()):
1823- LambdaTypeTree (tparams, toplevelTyp())
1824+ LambdaTypeTree (tparams.mapConserve(stripContextBounds( " type lambdas " )) , toplevelTyp())
18241825 else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
18251826 val arrowOffset = in.skipToken()
18261827 val body = toplevelTyp(nestedIntoOK(in.token))
@@ -1836,6 +1837,13 @@ object Parsers {
18361837 typeRest(infixType(inContextBound))
18371838 end typ
18381839
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+
18391847 private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
18401848 val isVarianceAnnotated = name.startsWith(" +" ) || name.startsWith(" -" )
18411849 // We remove the variance marker from the name without passing along the specified variance at all
@@ -3498,7 +3506,7 @@ object Parsers {
34983506 *
34993507 * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
35003508 * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3501- * (id | ‘_’) [HkTypePamClause ] TypeBounds
3509+ * (id | ‘_’) [HkTypeParamClause ] TypeBounds
35023510 */
35033511 def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
35043512
0 commit comments