@@ -1062,11 +1062,11 @@ object Parsers {
10621062 def typeRHS (): Tree =
10631063 if (in.token == IF )
10641064 atPos(in.skipToken()) {
1065- val cond = typeRHS ()
1065+ val cond = expr ()
10661066 accept(THEN )
10671067 val thenp = typeRHS()
10681068 accept(ELSE )
1069- val elsep = expr ()
1069+ val elsep = typeRHS ()
10701070 If (cond, thenp, elsep)
10711071 }
10721072 else toplevelTyp()
@@ -2200,7 +2200,7 @@ object Parsers {
22002200 Block (stats, Literal (Constant (())))
22012201 }
22022202
2203- /** TypeDcl ::= id [TypTypeParamClause] {DefParamClause} [‘:’ Type] ‘=’ TypeRHS
2203+ /** TypeDcl ::= id [TypTypeParamClause] {DefParamClause} TypeBounds ‘=’ TypeRHS
22042204 * | id [HkTypeParamClause] TypeBounds
22052205 */
22062206 def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
@@ -2209,23 +2209,22 @@ object Parsers {
22092209 val name = ident().toTypeName
22102210 val tparams = typeParamClauseOpt(ParamOwner .Type )
22112211 val vparamss = paramClauses(ParamOwner .Type )
2212- val tpt = typedOpt()
2213- val isDef = ! vparamss.isEmpty || ! tpt.isEmpty
2214- in.token match {
2215- case EQUALS =>
2212+ val isBounded = in.token == SUPERTYPE || in.token == SUBTYPE
2213+ val bounds = typeBounds()
2214+ val res =
2215+ if (in.token == EQUALS ) {
22162216 in.nextToken()
22172217 val rhs = typeRHS()
2218- val res =
2219- if (isTypeDefRHS(rhs) || isDef) DefDef (name, tparams, vparamss, tpt, rhs)
2220- else TypeDef (name, lambdaAbstract(tparams, rhs))
2221- res.withMods(mods).setComment(in.getDocComment(start))
2222- case SUPERTYPE | SUBTYPE | SEMI | NEWLINE | NEWLINES | COMMA | RBRACE | EOF =>
2223- if (isDef) syntaxError(" `=' expected" )
2224- TypeDef (name, lambdaAbstract(tparams, typeBounds())).withMods(mods).setComment(in.getDocComment(start))
2225- case _ =>
2226- syntaxErrorOrIncomplete(ExpectedTypeBoundOrEquals (in.token))
2227- EmptyTree
2228- }
2218+ if (isTypeDefRHS(rhs) || isBounded || vparamss.nonEmpty)
2219+ DefDef (name, tparams, vparamss, bounds, rhs)
2220+ else
2221+ TypeDef (name, lambdaAbstract(tparams, rhs))
2222+ }
2223+ else {
2224+ if (vparamss.nonEmpty) syntaxError(" `=' expected" )
2225+ TypeDef (name, lambdaAbstract(tparams, bounds))
2226+ }
2227+ res.withMods(mods).setComment(in.getDocComment(start))
22292228 }
22302229 }
22312230
0 commit comments