@@ -994,8 +994,8 @@ object Parsers {
994
994
skipParams()
995
995
lookahead.isColon
996
996
&& {
997
- ! in.featureEnabled( Feature .modularity )
998
- || { // with modularity language import , a `:` at EOL after an identifier represents a single identifier given
997
+ ! sourceVersion.isAtLeast(`3.6` )
998
+ || { // in the new given syntax , a `:` at EOL after an identifier represents a single identifier given
999
999
// Example:
1000
1000
// given C:
1001
1001
// def f = ...
@@ -1833,7 +1833,7 @@ object Parsers {
1833
1833
infixOps(t, canStartInfixTypeTokens, operand, Location .ElseWhere , ParseKind .Type ,
1834
1834
isOperator = ! followingIsVararg()
1835
1835
&& ! isPureArrow
1836
- && ! (isIdent(nme.as) && in.featureEnabled( Feature .modularity ))
1836
+ && ! (isIdent(nme.as) && sourceVersion.isAtLeast(`3.6` ))
1837
1837
&& nextCanFollowOperator(canStartInfixTypeTokens))
1838
1838
1839
1839
/** RefinedType ::= WithType {[nl] Refinement} [`^` CaptureSet]
@@ -2226,20 +2226,30 @@ object Parsers {
2226
2226
def contextBound (pname : TypeName ): Tree =
2227
2227
val t = toplevelTyp()
2228
2228
val ownName =
2229
- if isIdent(nme.as) && in.featureEnabled( Feature .modularity ) then
2229
+ if isIdent(nme.as) && sourceVersion.isAtLeast(`3.6` ) then
2230
2230
in.nextToken()
2231
2231
ident()
2232
2232
else EmptyTermName
2233
2233
ContextBoundTypeTree (t, pname, ownName)
2234
2234
2235
- /** ContextBounds ::= ContextBound | `{` ContextBound {`,` ContextBound} `}`
2235
+ /** ContextBounds ::= ContextBound [`:` ContextBounds]
2236
+ * | `{` ContextBound {`,` ContextBound} `}`
2236
2237
*/
2237
2238
def contextBounds (pname : TypeName ): List [Tree ] =
2238
2239
if in.isColon then
2239
2240
in.nextToken()
2240
- if in.token == LBRACE && in.featureEnabled( Feature .modularity )
2241
+ if in.token == LBRACE && sourceVersion.isAtLeast(`3.6` )
2241
2242
then inBraces(commaSeparated(() => contextBound(pname)))
2242
- else contextBound(pname) :: contextBounds(pname)
2243
+ else
2244
+ val bound = contextBound(pname)
2245
+ val rest =
2246
+ if in.isColon then
2247
+ report.errorOrMigrationWarning(
2248
+ em " Multiple context bounds should be enclosed in `{ ... }` " ,
2249
+ in.sourcePos(), MigrationVersion .GivenSyntax )
2250
+ contextBounds(pname)
2251
+ else Nil
2252
+ bound :: rest
2243
2253
else if in.token == VIEWBOUND then
2244
2254
report.errorOrMigrationWarning(
2245
2255
em " view bounds `<%' are no longer supported, use a context bound `:' instead " ,
@@ -4014,7 +4024,7 @@ object Parsers {
4014
4024
case SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | OUTDENT | EOF =>
4015
4025
makeTypeDef(typeAndCtxBounds(tname))
4016
4026
case _ if (staged & StageKind .QuotedPattern ) != 0
4017
- || in.featureEnabled( Feature .modularity ) && in.isColon =>
4027
+ || sourceVersion.isAtLeast(`3.6` ) && in.isColon =>
4018
4028
makeTypeDef(typeAndCtxBounds(tname))
4019
4029
case _ =>
4020
4030
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals (in.token))
@@ -4189,7 +4199,7 @@ object Parsers {
4189
4199
def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
4190
4200
var mods1 = addMod(mods, givenMod)
4191
4201
val nameStart = in.offset
4192
- var newSyntaxAllowed = in.featureEnabled( Feature .modularity )
4202
+ var newSyntaxAllowed = sourceVersion.isAtLeast(`3.6` )
4193
4203
val hasEmbeddedColon = ! in.isColon && followingIsGivenDefWithColon()
4194
4204
val name = if isIdent && hasEmbeddedColon then ident() else EmptyTermName
4195
4205
@@ -4260,6 +4270,9 @@ object Parsers {
4260
4270
in.nextToken()
4261
4271
newSignature()
4262
4272
else if hasEmbeddedColon then
4273
+ report.errorOrMigrationWarning(
4274
+ em " This old given syntax is no longer supported; use `=>` instead of `:` " ,
4275
+ in.sourcePos(), MigrationVersion .GivenSyntax )
4263
4276
newSyntaxAllowed = false
4264
4277
val tparamsOld = typeParamClauseOpt(ParamOwner .Given )
4265
4278
newLineOpt()
@@ -4294,10 +4307,10 @@ object Parsers {
4294
4307
if name.isEmpty then
4295
4308
syntaxError(em " Anonymous given cannot be abstract, or maybe you want to define a concrete given and are missing a `()` argument? " , in.lastOffset)
4296
4309
if newSyntaxAllowed then
4297
- warning (
4298
- em """ This defines an abstract given, which is deprecated . Use a `deferred` given instead.
4310
+ report.errorOrMigrationWarning (
4311
+ em """ This defines an abstract given, which is no longer supported . Use a `deferred` given instead.
4299
4312
|Or, if you intend to define a concrete given, follow the type with `()` arguments. """ ,
4300
- in.lastOffset)
4313
+ in.sourcePos(in. lastOffset), MigrationVersion . GivenSyntax )
4301
4314
DefDef (name, adjustDefParams(joinParams(tparams, vparamss)), parents.head, EmptyTree )
4302
4315
else
4303
4316
// structural instance
@@ -4487,6 +4500,9 @@ object Parsers {
4487
4500
4488
4501
/** with Template, with EOL <indent> interpreted */
4489
4502
def withTemplate (constr : DefDef , parents : List [Tree ]): Template =
4503
+ report.errorOrMigrationWarning(
4504
+ em " Given member definitions starting with `with` are no longer supported; use `{...}` or `:` followed by newline instead " ,
4505
+ in.sourcePos(), MigrationVersion .GivenSyntax )
4490
4506
accept(WITH )
4491
4507
val (self, stats) = templateBody(parents, rewriteWithColon = false )
4492
4508
Template (constr, parents, Nil , self, stats)
0 commit comments