@@ -907,7 +907,7 @@ object Parsers {
907
907
lookahead.nextToken()
908
908
while lookahead.token == LPAREN || lookahead.token == LBRACKET do
909
909
lookahead.skipParens()
910
- lookahead.token == COLON
910
+ lookahead.token == COLON || lookahead.token == SUBTYPE
911
911
912
912
/* --------- OPERAND/OPERATOR STACK --------------------------------------- */
913
913
@@ -3232,7 +3232,7 @@ object Parsers {
3232
3232
case ENUM =>
3233
3233
enumDef(start, posMods(start, mods | Enum ))
3234
3234
case GIVEN =>
3235
- instanceDef (start, mods, atSpan(in.skipToken()) { Mod .Given () })
3235
+ givenDef (start, mods, atSpan(in.skipToken()) { Mod .Given () })
3236
3236
case _ =>
3237
3237
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition ())
3238
3238
EmptyTree
@@ -3336,19 +3336,13 @@ object Parsers {
3336
3336
syntaxError(em " extension clause must start with a single regular parameter " , start)
3337
3337
3338
3338
3339
- /** OLD:
3340
- * GivenDef ::= [id] [DefTypeParamClause] GivenBody
3341
- * GivenBody ::= [‘as ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
3342
- * | ‘as’ Type {GivenParamClause} ‘=’ Expr
3343
- * | ‘(’ DefParam ‘)’ TemplateBody
3344
- * NEW:
3345
- * GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
3339
+ /** GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
3346
3340
* | [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [TemplateBody]
3347
3341
* | [id ‘:’] [ExtParamClause] TemplateBody
3348
3342
* GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
3349
3343
* ExtParamClause ::= [DefTypeParamClause] DefParamClause {GivenParamClause}
3350
3344
*/
3351
- def instanceDef (start : Offset , mods : Modifiers , instanceMod : Mod ) = atSpan(start, nameStart) {
3345
+ def givenDef (start : Offset , mods : Modifiers , instanceMod : Mod ) = atSpan(start, nameStart) {
3352
3346
var mods1 = addMod(mods, instanceMod)
3353
3347
val hasGivenSig = followingIsGivenSig()
3354
3348
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
@@ -3382,6 +3376,11 @@ object Parsers {
3382
3376
Nil
3383
3377
else
3384
3378
tokenSeparated(COMMA , constrApp)
3379
+ else if in.token == SUBTYPE then
3380
+ if ! mods.is(Inline ) then
3381
+ syntaxError(" `<:' is only allowed for given with `inline' modifier" )
3382
+ in.nextToken()
3383
+ TypeBoundsTree (EmptyTree , toplevelTyp()) :: Nil
3385
3384
else if name.isEmpty && in.token != LBRACE then
3386
3385
tokenSeparated(COMMA , constrApp)
3387
3386
else Nil
@@ -3392,7 +3391,9 @@ object Parsers {
3392
3391
mods1 |= Final
3393
3392
DefDef (name, tparams, vparamss, parents.head, subExpr())
3394
3393
else
3395
- // println(i"given $name $hasExtensionParams $hasGivenSig")
3394
+ parents match
3395
+ case TypeBoundsTree (_, _) :: _ => syntaxError(" `=' expected" )
3396
+ case _ =>
3396
3397
possibleTemplateStart()
3397
3398
if ! hasExtensionParams then
3398
3399
tparams = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
0 commit comments