@@ -903,7 +903,7 @@ object Parsers {
903
903
lookahead.nextToken()
904
904
while lookahead.token == LPAREN || lookahead.token == LBRACKET do
905
905
lookahead.skipParens()
906
- lookahead.token == COLON
906
+ lookahead.token == COLON || lookahead.token == SUBTYPE
907
907
908
908
/* --------- OPERAND/OPERATOR STACK --------------------------------------- */
909
909
@@ -3238,7 +3238,7 @@ object Parsers {
3238
3238
case ENUM =>
3239
3239
enumDef(start, posMods(start, mods | Enum ))
3240
3240
case GIVEN =>
3241
- instanceDef (start, mods, atSpan(in.skipToken()) { Mod .Given () })
3241
+ givenDef (start, mods, atSpan(in.skipToken()) { Mod .Given () })
3242
3242
case _ =>
3243
3243
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition ())
3244
3244
EmptyTree
@@ -3342,19 +3342,13 @@ object Parsers {
3342
3342
syntaxError(em " extension clause must start with a single regular parameter " , start)
3343
3343
3344
3344
3345
- /** OLD:
3346
- * GivenDef ::= [id] [DefTypeParamClause] GivenBody
3347
- * GivenBody ::= [‘as ConstrApp {‘,’ ConstrApp }] {GivenParamClause} [TemplateBody]
3348
- * | ‘as’ Type {GivenParamClause} ‘=’ Expr
3349
- * | ‘(’ DefParam ‘)’ TemplateBody
3350
- * NEW:
3351
- * GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
3345
+ /** GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
3352
3346
* | [GivenSig ‘:’] [ConstrApp {‘,’ ConstrApp }] [TemplateBody]
3353
3347
* | [id ‘:’] [ExtParamClause] TemplateBody
3354
3348
* GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause}
3355
3349
* ExtParamClause ::= [DefTypeParamClause] DefParamClause {GivenParamClause}
3356
3350
*/
3357
- def instanceDef (start : Offset , mods : Modifiers , instanceMod : Mod ) = atSpan(start, nameStart) {
3351
+ def givenDef (start : Offset , mods : Modifiers , instanceMod : Mod ) = atSpan(start, nameStart) {
3358
3352
var mods1 = addMod(mods, instanceMod)
3359
3353
val hasGivenSig = followingIsGivenSig()
3360
3354
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
@@ -3388,6 +3382,11 @@ object Parsers {
3388
3382
Nil
3389
3383
else
3390
3384
tokenSeparated(COMMA , constrApp)
3385
+ else if in.token == SUBTYPE then
3386
+ if ! mods.is(Inline ) then
3387
+ syntaxError(" `<:' is only allowed for given with `inline' modifier" )
3388
+ in.nextToken()
3389
+ TypeBoundsTree (EmptyTree , toplevelTyp()) :: Nil
3391
3390
else if name.isEmpty && in.token != LBRACE then
3392
3391
tokenSeparated(COMMA , constrApp)
3393
3392
else Nil
@@ -3398,7 +3397,9 @@ object Parsers {
3398
3397
mods1 |= Final
3399
3398
DefDef (name, tparams, vparamss, parents.head, subExpr())
3400
3399
else
3401
- // println(i"given $name $hasExtensionParams $hasGivenSig")
3400
+ parents match
3401
+ case TypeBoundsTree (_, _) :: _ => syntaxError(" `=' expected" )
3402
+ case _ =>
3402
3403
possibleTemplateStart()
3403
3404
if ! hasExtensionParams then
3404
3405
tparams = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
0 commit comments