Skip to content

Commit 72f0fa5

Browse files
committed
Allow parsers to parse type signatures with erased parameters
We only allow `erased` on signatures with parameter names for now: type Allowed = (x: Int, erased y: Int) => Int type Disallowed = (Int, erased Int) => Int
1 parent 1eff9a5 commit 72f0fa5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ object Parsers {
14951495
if isByNameType(tpt) then
14961496
syntaxError(em"parameter of type lambda may not be call-by-name", tpt.span)
14971497
TermLambdaTypeTree(params.asInstanceOf[List[ValDef]], resultType)
1498-
else if imods.isOneOf(Given | Erased | Impure) then
1498+
else if imods.isOneOf(Given | Impure) then
14991499
if imods.is(Given) && params.isEmpty then
15001500
syntaxError(em"context function types require at least one parameter", paramSpan)
15011501
FunctionWithMods(params, resultType, imods)
@@ -1516,16 +1516,25 @@ object Parsers {
15161516
functionRest(Nil)
15171517
}
15181518
else {
1519-
if isErased then imods = addModifier(imods)
15201519
val paramStart = in.offset
1520+
val firstMods = if isErased then addModifier(imods) else imods
15211521
val ts = in.currentRegion.withCommasExpected {
15221522
funArgType() match
15231523
case Ident(name) if name != tpnme.WILDCARD && in.isColon =>
15241524
isValParamList = true
1525+
def funParam(start: Offset, mods: Modifiers) = {
1526+
atSpan(start) {
1527+
val mods1 = if isErased then addModifier(mods) else mods
1528+
typedFunParam(in.offset, ident(), mods1)
1529+
}
1530+
}
15251531
commaSeparatedRest(
1526-
typedFunParam(paramStart, name.toTermName, imods),
1527-
() => typedFunParam(in.offset, ident(), imods))
1532+
typedFunParam(paramStart, name.toTermName, firstMods),
1533+
() => funParam(in.offset, imods))
15281534
case t =>
1535+
// For now we just reject `erased` in (T, U) => V definitions (i.e. you need parameter names)
1536+
if firstMods.is(Erased) then
1537+
syntaxError(em"Implementation restriction: erased parameters are not allowed without parameter names", paramStart)
15291538
commaSeparatedRest(t, funArgType)
15301539
}
15311540
accept(RPAREN)

0 commit comments

Comments
 (0)