-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix errors in the global initialization checker when compiling bootstrapped dotty #23429
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
olhotak
merged 2 commits into
scala:main
from
dotty-staging:fix-errors-when-testing-global-init-checker
Jul 2, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,15 +532,15 @@ class Objects(using Context @constructorOnly): | |
case env: EnvRef => | ||
env.initVal(x, value) | ||
case ref: Ref => | ||
ref.initVal(x, value) // TODO: This is possible for match statement in class body. Report warning? | ||
ref.initVal(x, value) // This is possible for match statement in class body. | ||
|
||
def setLocalVar(x: Symbol, value: Value)(using scope: Scope, ctx: Context, heap: Heap.MutableData, envMap: EnvMap.EnvMapMutableData): Unit = | ||
assert(x.is(Flags.Mutable, butNot = Flags.Param), "Only local mutable variable allowed") | ||
scope match | ||
case env: EnvRef => | ||
env.initVar(x, value) | ||
case ref: Ref => | ||
ref.initVar(x, value) // TODO: This is possible for match statement in class body. Report warning? | ||
ref.initVar(x, value) // This is possible for match statement in class body. | ||
|
||
/** | ||
* Resolve the environment by searching for a given symbol. | ||
|
@@ -986,15 +986,7 @@ class Objects(using Context @constructorOnly): | |
// Assume such method is pure. Check return type, only try to analyze body if return type is not safe | ||
val target = resolve(v.typeSymbol.asClass, meth) | ||
val targetType = target.denot.info | ||
assert(targetType.isInstanceOf[ExprType] || targetType.isInstanceOf[MethodType], | ||
"Unexpected type! Receiver = " + v.show + ", meth = " + target + ", type = " + targetType) | ||
val returnType = | ||
if targetType.isInstanceOf[ExprType] then | ||
// corresponds to parameterless method like `def meth: ExprType[T]` | ||
// See pos/toDouble.scala | ||
targetType.asInstanceOf[ExprType].resType | ||
else | ||
targetType.asInstanceOf[MethodType].resType | ||
val returnType = targetType.finalResultType | ||
val typeSymbol = SafeValue.getSafeTypeSymbol(returnType) | ||
if typeSymbol.isDefined then | ||
// since method is pure and return type is safe, no need to analyze method body | ||
|
@@ -1326,7 +1318,8 @@ class Objects(using Context @constructorOnly): | |
report.warning("[Internal error] top-level class should have `Package` as outer, class = " + klass.show + ", outer = " + outer.show + ", " + Trace.show, Trace.position) | ||
(Bottom, Env.NoEnv) | ||
else | ||
val outerCls = klass.owner.enclosingClass.asClass | ||
// enclosingClass is specially handled for java static terms, so use `lexicallyEnclosingClass` here | ||
val outerCls = klass.owner.lexicallyEnclosingClass.asClass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch and comment 👍 |
||
// When `klass` is directly nested in `outerCls`, `outerCls`.enclosingMethod returns its primary constructor | ||
if klass.owner.enclosingMethod == outerCls.primaryConstructor then | ||
(outer, Env.NoEnv) | ||
|
@@ -1813,6 +1806,7 @@ class Objects(using Context @constructorOnly): | |
val toSeqResTp = resultTp.memberInfo(selectors.last).finalResultType | ||
evalSeqPatterns(toSeqRes, toSeqResTp, elemTp, seqPats) | ||
end if | ||
// TODO: refactor the code of product sequence match, avoid passing NoType to parameter elemTp in evalSeqPatterns | ||
|
||
else | ||
// distribute unapply to patterns | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
enum FileExtension(val toLowerCase: String): | ||
case Tasty extends FileExtension("tasty") | ||
case Betasty extends FileExtension("betasty") | ||
case Class extends FileExtension("class") | ||
case Jar extends FileExtension("jar") | ||
case Scala extends FileExtension("scala") | ||
case ScalaScript extends FileExtension("sc") | ||
case Java extends FileExtension("java") | ||
case Zip extends FileExtension("zip") | ||
case Inc extends FileExtension("inc") | ||
case Empty extends FileExtension("") | ||
|
||
/** Fallback extension */ | ||
case External(override val toLowerCase: String) extends FileExtension(toLowerCase) | ||
|
||
object O: | ||
val a = FileExtension.Empty |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification 👍