@@ -3930,51 +3930,54 @@ object Parsers {
3930
3930
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3931
3931
}
3932
3932
3933
- /** TypeDef ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type]
3933
+ /** TypeDef ::= id [TypeParamClause] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3934
3934
*/
3935
3935
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
3936
3936
newLinesOpt()
3937
3937
atSpan(start, nameStart) {
3938
3938
val nameIdent = typeIdent()
3939
+ val tname = nameIdent.name.asTypeName
3939
3940
val tparams = typeParamClauseOpt(ParamOwner .Type )
3940
3941
val vparamss = funParamClauses()
3942
+
3941
3943
def makeTypeDef (rhs : Tree ): Tree = {
3942
3944
val rhs1 = lambdaAbstractAll(tparams :: vparamss, rhs)
3943
3945
val tdef = TypeDef (nameIdent.name.toTypeName, rhs1)
3944
3946
if (nameIdent.isBackquoted)
3945
3947
tdef.pushAttachment(Backquoted , ())
3946
3948
finalizeDef(tdef, mods, start)
3947
3949
}
3950
+
3948
3951
in.token match {
3949
3952
case EQUALS =>
3950
3953
in.nextToken()
3951
3954
makeTypeDef(toplevelTyp())
3952
3955
case SUBTYPE | SUPERTYPE =>
3953
- val bounds = typeBounds()
3954
- if (in.token == EQUALS ) {
3955
- val eqOffset = in.skipToken()
3956
- var rhs = toplevelTyp()
3957
- rhs match {
3958
- case mtt : MatchTypeTree =>
3959
- bounds match {
3960
- case TypeBoundsTree (EmptyTree , upper, _) =>
3961
- rhs = MatchTypeTree (upper, mtt.selector, mtt.cases)
3962
- case _ =>
3963
- syntaxError(em " cannot combine lower bound and match type alias " , eqOffset)
3964
- }
3965
- case _ =>
3966
- if mods.is(Opaque ) then
3967
- rhs = TypeBoundsTree (bounds.lo, bounds.hi, rhs)
3968
- else
3969
- syntaxError(em " cannot combine bound and alias " , eqOffset)
3970
- }
3971
- makeTypeDef(rhs)
3972
- }
3973
- else makeTypeDef(bounds)
3956
+ typeAndCtxBounds(tname) match
3957
+ case bounds : TypeBoundsTree if in.token == EQUALS =>
3958
+ val eqOffset = in.skipToken()
3959
+ var rhs = toplevelTyp()
3960
+ rhs match {
3961
+ case mtt : MatchTypeTree =>
3962
+ bounds match {
3963
+ case TypeBoundsTree (EmptyTree , upper, _) =>
3964
+ rhs = MatchTypeTree (upper, mtt.selector, mtt.cases)
3965
+ case _ =>
3966
+ syntaxError(em " cannot combine lower bound and match type alias " , eqOffset)
3967
+ }
3968
+ case _ =>
3969
+ if mods.is(Opaque ) then
3970
+ rhs = TypeBoundsTree (bounds.lo, bounds.hi, rhs)
3971
+ else
3972
+ syntaxError(em " cannot combine bound and alias " , eqOffset)
3973
+ }
3974
+ makeTypeDef(rhs)
3975
+ case bounds => makeTypeDef(bounds)
3974
3976
case SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | OUTDENT | EOF =>
3975
- makeTypeDef(typeBounds())
3976
- case _ if (staged & StageKind .QuotedPattern ) != 0 =>
3977
- makeTypeDef(typeBounds())
3977
+ makeTypeDef(typeAndCtxBounds(tname))
3978
+ case _ if (staged & StageKind .QuotedPattern ) != 0
3979
+ || in.featureEnabled(Feature .modularity) && in.isColon =>
3980
+ makeTypeDef(typeAndCtxBounds(tname))
3978
3981
case _ =>
3979
3982
syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals (in.token))
3980
3983
return EmptyTree // return to avoid setting the span to EmptyTree
0 commit comments