@@ -1062,11 +1062,11 @@ object Parsers {
1062
1062
def typeRHS (): Tree =
1063
1063
if (in.token == IF )
1064
1064
atPos(in.skipToken()) {
1065
- val cond = typeRHS ()
1065
+ val cond = expr ()
1066
1066
accept(THEN )
1067
1067
val thenp = typeRHS()
1068
1068
accept(ELSE )
1069
- val elsep = expr ()
1069
+ val elsep = typeRHS ()
1070
1070
If (cond, thenp, elsep)
1071
1071
}
1072
1072
else toplevelTyp()
@@ -2200,7 +2200,7 @@ object Parsers {
2200
2200
Block (stats, Literal (Constant (())))
2201
2201
}
2202
2202
2203
- /** TypeDcl ::= id [TypTypeParamClause] {DefParamClause} [‘:’ Type] ‘=’ TypeRHS
2203
+ /** TypeDcl ::= id [TypTypeParamClause] {DefParamClause} TypeBounds ‘=’ TypeRHS
2204
2204
* | id [HkTypeParamClause] TypeBounds
2205
2205
*/
2206
2206
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
@@ -2209,23 +2209,22 @@ object Parsers {
2209
2209
val name = ident().toTypeName
2210
2210
val tparams = typeParamClauseOpt(ParamOwner .Type )
2211
2211
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 ) {
2216
2216
in.nextToken()
2217
2217
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))
2229
2228
}
2230
2229
}
2231
2230
0 commit comments