Skip to content

Commit ee9b83e

Browse files
committed
Fix safe-init error in ParamOwner
When bootstrapping the compiler with the `-Ysafe-init` flag, we would get the following error: ``` [error] -- Error: /Users/rrampersad/Documents/school/URA/dotty/compiler/src/dotty/tools/dotc/parsing/Parsers.scala:53:45 [error] 53 | val Class, Type, TypeParam, Def: Value = Value [error] | ^^^^^ [error] |Calling the external method method Value may cause initialization errors. ``` This error orginates from the Scala 2 `Enumeration` class definition. In order to circumvent this issue, we instead define `ParamOwner` using a Scala 3 enum. This eliminates the error. Review by @liufengyun
1 parent a05ff76 commit ee9b83e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ object Parsers {
4949
case InBlock extends Location(false, false, false)
5050
case ElseWhere extends Location(false, false, false)
5151

52-
@sharable object ParamOwner extends Enumeration {
53-
val Class, Type, TypeParam, Def: Value = Value
54-
}
52+
enum ParamOwner:
53+
case Class, Type, TypeParam, Def
5554

5655
type StageKind = Int
5756
object StageKind {
@@ -2927,7 +2926,7 @@ object Parsers {
29272926
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
29282927
* HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
29292928
*/
2930-
def typeParamClause(ownerKind: ParamOwner.Value): List[TypeDef] = inBrackets {
2929+
def typeParamClause(ownerKind: ParamOwner): List[TypeDef] = inBrackets {
29312930

29322931
def variance(vflag: FlagSet): FlagSet =
29332932
if ownerKind == ParamOwner.Def || ownerKind == ParamOwner.TypeParam then
@@ -2962,7 +2961,7 @@ object Parsers {
29622961
commaSeparated(() => typeParam())
29632962
}
29642963

2965-
def typeParamClauseOpt(ownerKind: ParamOwner.Value): List[TypeDef] =
2964+
def typeParamClauseOpt(ownerKind: ParamOwner): List[TypeDef] =
29662965
if (in.token == LBRACKET) typeParamClause(ownerKind) else Nil
29672966

29682967
/** ContextTypes ::= FunArgType {‘,’ FunArgType}

0 commit comments

Comments
 (0)