@@ -3888,51 +3888,54 @@ object Parsers {
3888
3888
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3889
3889
}
3890
3890
3891
- /** TypeDef ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type]
3891
+ /** TypeDef ::= id [TypeParamClause] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3892
3892
*/
3893
3893
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
3894
3894
newLinesOpt()
3895
3895
atSpan(start, nameStart) {
3896
3896
val nameIdent = typeIdent()
3897
+ val tname = nameIdent.name.asTypeName
3897
3898
val tparams = typeParamClauseOpt(ParamOwner .Type )
3898
3899
val vparamss = funParamClauses()
3900
+
3899
3901
def makeTypeDef (rhs : Tree ): Tree = {
3900
3902
val rhs1 = lambdaAbstractAll(tparams :: vparamss, rhs)
3901
3903
val tdef = TypeDef (nameIdent.name.toTypeName, rhs1)
3902
3904
if (nameIdent.isBackquoted)
3903
3905
tdef.pushAttachment(Backquoted , ())
3904
3906
finalizeDef(tdef, mods, start)
3905
3907
}
3908
+
3906
3909
in.token match {
3907
3910
case EQUALS =>
3908
3911
in.nextToken()
3909
3912
makeTypeDef(toplevelTyp())
3910
3913
case SUBTYPE | SUPERTYPE =>
3911
- val bounds = typeBounds()
3912
- if (in.token == EQUALS ) {
3913
- val eqOffset = in.skipToken()
3914
- var rhs = toplevelTyp()
3915
- rhs match {
3916
- case mtt : MatchTypeTree =>
3917
- bounds match {
3918
- case TypeBoundsTree (EmptyTree , upper, _) =>
3919
- rhs = MatchTypeTree (upper, mtt.selector, mtt.cases)
3920
- case _ =>
3921
- syntaxError(em " cannot combine lower bound and match type alias " , eqOffset)
3922
- }
3923
- case _ =>
3924
- if mods.is(Opaque ) then
3925
- rhs = TypeBoundsTree (bounds.lo, bounds.hi, rhs)
3926
- else
3927
- syntaxError(em " cannot combine bound and alias " , eqOffset)
3928
- }
3929
- makeTypeDef(rhs)
3930
- }
3931
- else makeTypeDef(bounds)
3914
+ typeAndCtxBounds(tname) match
3915
+ case bounds : TypeBoundsTree if in.token == EQUALS =>
3916
+ val eqOffset = in.skipToken()
3917
+ var rhs = toplevelTyp()
3918
+ rhs match {
3919
+ case mtt : MatchTypeTree =>
3920
+ bounds match {
3921
+ case TypeBoundsTree (EmptyTree , upper, _) =>
3922
+ rhs = MatchTypeTree (upper, mtt.selector, mtt.cases)
3923
+ case _ =>
3924
+ syntaxError(em " cannot combine lower bound and match type alias " , eqOffset)
3925
+ }
3926
+ case _ =>
3927
+ if mods.is(Opaque ) then
3928
+ rhs = TypeBoundsTree (bounds.lo, bounds.hi, rhs)
3929
+ else
3930
+ syntaxError(em " cannot combine bound and alias " , eqOffset)
3931
+ }
3932
+ makeTypeDef(rhs)
3933
+ case bounds => makeTypeDef(bounds)
3932
3934
case SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | OUTDENT | EOF =>
3933
- makeTypeDef(typeBounds())
3934
- case _ if (staged & StageKind .QuotedPattern ) != 0 =>
3935
- makeTypeDef(typeBounds())
3935
+ makeTypeDef(typeAndCtxBounds(tname))
3936
+ case _ if (staged & StageKind .QuotedPattern ) != 0
3937
+ || in.featureEnabled(Feature .modularity) && in.isColon =>
3938
+ makeTypeDef(typeAndCtxBounds(tname))
3936
3939
case _ =>
3937
3940
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals (in.token))
3938
3941
return EmptyTree // return to avoid setting the span to EmptyTree
0 commit comments