@@ -1364,6 +1364,7 @@ object Parsers {
1364
1364
val start = in.offset
1365
1365
var imods = Modifiers ()
1366
1366
def functionRest (params : List [Tree ]): Tree =
1367
+ val paramSpan = Span (start, in.lastOffset)
1367
1368
atSpan(start, in.offset) {
1368
1369
if in.token == TLARROW then
1369
1370
if ! imods.flags.isEmpty || params.isEmpty then
@@ -1382,14 +1383,16 @@ object Parsers {
1382
1383
accept(ARROW )
1383
1384
val t = typ()
1384
1385
1385
- if (imods.isOneOf(Given | Erased )) new FunctionWithMods (params, t, imods)
1386
- else if (ctx.settings.YkindProjector .value) {
1386
+ if imods.isOneOf(Given | Erased ) then
1387
+ if imods.is(Given ) && params.isEmpty then
1388
+ syntaxError(" context function types require at least one parameter" , paramSpan)
1389
+ new FunctionWithMods (params, t, imods)
1390
+ else if ctx.settings.YkindProjector .value then
1387
1391
val (newParams :+ newT, tparams) = replaceKindProjectorPlaceholders(params :+ t)
1388
1392
1389
1393
lambdaAbstract(tparams, Function (newParams, newT))
1390
- } else {
1394
+ else
1391
1395
Function (params, t)
1392
- }
1393
1396
}
1394
1397
def funArgTypesRest (first : Tree , following : () => Tree ) = {
1395
1398
val buf = new ListBuffer [Tree ] += first
@@ -1904,10 +1907,7 @@ object Parsers {
1904
1907
1905
1908
def expr (location : Location ): Tree = {
1906
1909
val start = in.offset
1907
- def isSpecialClosureStart =
1908
- val lookahead = in.LookaheadScanner ()
1909
- lookahead.nextToken()
1910
- lookahead.isIdent(nme.using) || lookahead.token == ERASED
1910
+ def isSpecialClosureStart = in.lookahead.token == ERASED
1911
1911
if in.token == IMPLICIT then
1912
1912
closure(start, location, modifiers(BitSet (IMPLICIT )))
1913
1913
else if in.token == LPAREN && isSpecialClosureStart then
@@ -2137,9 +2137,7 @@ object Parsers {
2137
2137
else
2138
2138
openParens.change(LPAREN , 1 )
2139
2139
var mods1 = mods
2140
- if mods.flags.isEmpty then
2141
- if isIdent(nme.using) then mods1 = addMod(mods1, atSpan(in.skipToken()) { Mod .Given () })
2142
- if in.token == ERASED then mods1 = addModifier(mods1)
2140
+ if in.token == ERASED then mods1 = addModifier(mods1)
2143
2141
try
2144
2142
commaSeparated(() => binding(mods1))
2145
2143
finally
@@ -2188,7 +2186,12 @@ object Parsers {
2188
2186
2189
2187
def closureRest (start : Int , location : Location , params : List [Tree ]): Tree =
2190
2188
atSpan(start, in.offset) {
2191
- if in.token == CTXARROW then in.nextToken() else accept(ARROW )
2189
+ if in.token == CTXARROW then
2190
+ if params.isEmpty then
2191
+ syntaxError(" context function literals require at least one formal parameter" , Span (start, in.lastOffset))
2192
+ in.nextToken()
2193
+ else
2194
+ accept(ARROW )
2192
2195
Function (params, if (location == Location .InBlock ) block() else expr())
2193
2196
}
2194
2197
0 commit comments