Skip to content

Fix safe-init error in DesugarEnums #14571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2022

Conversation

Xavientois
Copy link
Contributor

When bootstrapping the compiler with the -Ysafe-init flag, we would
get the following error:

[error] -- Error: /Users/********/dotty/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala:20:39
[error] 20 |    val Simple, Object, Class: 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 CaseKind using a Scala 3 enum. While this does require enum comparisons using < or <= to explicitly compare the ordinal of the enum variant, it also eliminates the initialization error.

Review by @liufengyun

@bishabosha bishabosha requested review from bishabosha and liufengyun and removed request for bishabosha February 25, 2022 16:51
When bootstrapping the compiler with the `-Ysafe-init` flag, we would
get the following error:
```
[error] -- Error: /Users/********/dotty/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala:20:39
[error] 20 |    val Simple, Object, Class: 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 `CaseKind` using a Scala 3 enum. While this does require enum comparisons using `<` or `<=` to explicitly compare the `ordinal` of the enum variant, it also eliminates the initialization error.

Review by @liufengyun
@Xavientois Xavientois force-pushed the safe-init-for-case-kind-enum branch from 12bf690 to 15ec5b6 Compare February 25, 2022 16:57
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring 👍

@bishabosha bishabosha merged commit 361546c into scala:main Feb 26, 2022
@Xavientois Xavientois deleted the safe-init-for-case-kind-enum branch February 26, 2022 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants