@@ -1434,13 +1434,30 @@ object Parsers {
1434
1434
*/
1435
1435
def toplevelTyp (): Tree = rejectWildcardType(typ())
1436
1436
1437
- private def isFunction (tree : Tree ): Boolean = tree match {
1438
- case Parens (tree1) => isFunction (tree1)
1439
- case Block (Nil , tree1) => isFunction (tree1)
1440
- case _ : Function => true
1441
- case _ => false
1437
+ private def getFunction (tree : Tree ): Option [ Function ] = tree match {
1438
+ case Parens (tree1) => getFunction (tree1)
1439
+ case Block (Nil , tree1) => getFunction (tree1)
1440
+ case t : Function => Some (t)
1441
+ case _ => None
1442
1442
}
1443
1443
1444
+ private def checkFunctionNotErased (f : Function , context : String ) =
1445
+ def fail (span : Span ) =
1446
+ syntaxError(em " Implementation restriction: erased parameters are not supported in $context" , span)
1447
+ // erased parameter in type
1448
+ val hasErasedParam = f match
1449
+ case f : FunctionWithMods => f.hasErasedParams
1450
+ case _ => false
1451
+ if hasErasedParam then
1452
+ fail(f.span)
1453
+ // erased parameter in term
1454
+ val hasErasedMods = f.args.collectFirst {
1455
+ case v : ValDef if v.mods.is(Flags .Erased ) => v
1456
+ }
1457
+ hasErasedMods match
1458
+ case Some (param) => fail(param.span)
1459
+ case _ =>
1460
+
1444
1461
/** CaptureRef ::= ident | `this`
1445
1462
*/
1446
1463
def captureRef (): Tree =
@@ -1580,11 +1597,13 @@ object Parsers {
1580
1597
val arrowOffset = in.skipToken()
1581
1598
val body = toplevelTyp()
1582
1599
atSpan(start, arrowOffset) {
1583
- if (isFunction(body))
1584
- PolyFunction (tparams, body)
1585
- else {
1586
- syntaxError(em " Implementation restriction: polymorphic function types must have a value parameter " , arrowOffset)
1587
- Ident (nme.ERROR .toTypeName)
1600
+ getFunction(body) match {
1601
+ case Some (f) =>
1602
+ checkFunctionNotErased(f, " poly function" )
1603
+ PolyFunction (tparams, body)
1604
+ case None =>
1605
+ syntaxError(em " Implementation restriction: polymorphic function types must have a value parameter " , arrowOffset)
1606
+ Ident (nme.ERROR .toTypeName)
1588
1607
}
1589
1608
}
1590
1609
}
@@ -2113,12 +2132,13 @@ object Parsers {
2113
2132
val arrowOffset = accept(ARROW )
2114
2133
val body = expr(location)
2115
2134
atSpan(start, arrowOffset) {
2116
- if (isFunction(body))
2117
- PolyFunction (tparams, body)
2118
- else {
2119
- syntaxError(em " Implementation restriction: polymorphic function literals must have a value parameter " , arrowOffset)
2120
- errorTermTree(arrowOffset)
2121
- }
2135
+ getFunction(body) match
2136
+ case Some (f) =>
2137
+ checkFunctionNotErased(f, " poly function" )
2138
+ PolyFunction (tparams, f)
2139
+ case None =>
2140
+ syntaxError(em " Implementation restriction: polymorphic function literals must have a value parameter " , arrowOffset)
2141
+ errorTermTree(arrowOffset)
2122
2142
}
2123
2143
case _ =>
2124
2144
val saved = placeholderParams
0 commit comments