Skip to content

Commit c38dcaf

Browse files
author
EnzeXing
committed
Reorganize tests
1 parent 04dc65f commit c38dcaf

19 files changed

+66
-16
lines changed

Diff for: compiler/src/dotty/tools/dotc/Compiler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Compiler {
171171
val rctx =
172172
if ctx.settings.Xsemanticdb.value then
173173
ctx.addMode(Mode.ReadPositions)
174-
else if !ctx.settings.YcheckInitGlobal.isDefault then
174+
else if ctx.settings.YcheckInitGlobal.value then
175175
ctx.addMode(Mode.ReadPositions)
176176
else
177177
ctx

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ private sealed trait YSettings:
445445
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism.")
446446
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
447447
val YnoFlexibleTypes: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-flexible-types", "Disable turning nullable Java return types and parameter types into flexible types, which behave like abstract types with a nullable lower bound and non-nullable upper bound.")
448-
val YcheckInitGlobal: Setting[String] = ChoiceSetting(ForkSetting, "Ysafe-init-global", "[report-unknown, ignore-unknown]", "Check safe initialization of global objects.", List("report-unknown", "ignore-unknown", "off"), "off")
448+
val YcheckInitGlobal: Setting[Boolean] = BooleanSetting(ForkSetting, "Ysafe-init-global", "Check safe initialization of global objects.")
449449
val YrequireTargetName: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation.")
450450
val YrecheckTest: Setting[Boolean] = BooleanSetting(ForkSetting, "Yrecheck-test", "Run basic rechecking (internal test only).")
451451
val YccDebug: Setting[Boolean] = BooleanSetting(ForkSetting, "Ycc-debug", "Used in conjunction with captureChecking language import, debug info for captured references.")

Diff for: compiler/src/dotty/tools/dotc/core/Symbols.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ object Symbols extends SymUtils {
8585
denot.owner.isTerm || // no risk of leaking memory after a run for these
8686
denot.isOneOf(InlineOrProxy) || // need to keep inline info
8787
ctx.settings.Whas.checkInit || // initialization check
88-
!ctx.settings.YcheckInitGlobal.isDefault
88+
ctx.settings.YcheckInitGlobal.value
8989

9090
/** The last denotation of this symbol */
9191
private var lastDenot: SymDenotation = uninitialized

Diff for: compiler/src/dotty/tools/dotc/transform/init/Checker.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Checker extends Phase:
2929
override val runsAfter = Set(Pickler.name)
3030

3131
override def isEnabled(using Context): Boolean =
32-
super.isEnabled && (ctx.settings.Whas.checkInit || !ctx.settings.YcheckInitGlobal.isDefault)
32+
super.isEnabled && (ctx.settings.Whas.checkInit || ctx.settings.YcheckInitGlobal.value)
3333

3434
def traverse(traverser: InitTreeTraverser)(using Context): Boolean = monitor(phaseName):
3535
val unit = ctx.compilationUnit
@@ -53,7 +53,7 @@ class Checker extends Phase:
5353
if ctx.settings.Whas.checkInit then
5454
Semantic.checkClasses(classes)(using checkCtx)
5555

56-
if !ctx.settings.YcheckInitGlobal.isDefault then
56+
if ctx.settings.YcheckInitGlobal.value then
5757
val obj = new Objects
5858
obj.checkClasses(classes)(using checkCtx)
5959
}

Diff for: compiler/src/dotty/tools/dotc/transform/init/Objects.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ class Objects(using Context @constructorOnly):
712712

713713
/** Check if the checker option reports warnings about unknown code
714714
*/
715-
def reportUnknown(using context: Context): Boolean =
716-
context.settings.YcheckInitGlobal.value == "report-unknown"
715+
val reportUnknown: Boolean = false
716+
717717

718718
/** Handle method calls `e.m(args)`.
719719
*
@@ -932,7 +932,10 @@ class Objects(using Context @constructorOnly):
932932
UnknownValue
933933

934934
case v @ SafeValue(_) =>
935-
report.warning("[Internal error] Unexpected selection on safe value " + v.show + ", field = " + field.show + Trace.show, Trace.position)
935+
if v.typeSymbol != defn.NullClass then
936+
// selection on Null is sensible on AST level; no warning for it
937+
report.warning("[Internal error] Unexpected selection on safe value " + v.show + ", field = " + field.show + ". " + Trace.show, Trace.position)
938+
end if
936939
Bottom
937940

938941
case Package(packageSym) =>

Diff for: compiler/test/dotc/neg-init-global-scala2-library-tasty.excludelist

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
## See #18882
22
patmat.scala
33
t9312.scala
4-
unapplySeq-implicit-arg.scala
5-
unapplySeq-implicit-arg2.scala
6-
unapplySeq-implicit-arg3.scala
74
ScalaCheck.scala
85
mutable-read8.scala
96
TypeCast.scala

Diff for: compiler/test/dotty/tools/dotc/CompilationTests.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ class CompilationTests {
231231
// initialization tests
232232
@Test def checkInitGlobal: Unit = {
233233
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
234-
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global:ignore-unknown"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyExcludelisted)).checkWarnings()
235-
compileFilesInDir("tests/init-global/pos", defaultOptions.and("-Ysafe-init-global:ignore-unknown", "-Xfatal-warnings"), FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyExcludelisted)).checkCompile()
234+
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyExcludelisted)).checkWarnings()
235+
compileFilesInDir("tests/init-global/pos", defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings"), FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyExcludelisted)).checkCompile()
236+
if Properties.usingScalaLibraryTasty then
237+
compileFilesInDir("tests/init-global/warn-tasty", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyExcludelisted)).checkWarnings()
238+
compileFilesInDir("tests/init-global/pos-tasty", defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings"), FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyExcludelisted)).checkCompile()
239+
end if
236240
}
237241

238242
// initialization tests

Diff for: tests/init-global/pos-tasty/simple.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object O:
2+
val a: Int = 5
3+
val b = a.toDouble

Diff for: tests/init-global/pos/arithmetic.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object A:
2+
val a = f(10)
3+
def f(x: Int) = x * 2 + 5
File renamed without changes.
File renamed without changes.

Diff for: tests/init-global/warn/unapplySeq-implicit-arg.check renamed to tests/init-global/warn-tasty/unapplySeq-implicit-arg.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Warning: tests/init-global/warn/unapplySeq-implicit-arg.scala:11:20 -------------------------------------------------
1+
-- Warning: tests/init-global/warn-tasty/unapplySeq-implicit-arg.scala:11:20 -------------------------------------------
22
11 | val i2: Int = Seq(i2) match // warn
33
| ^^
44
| Access uninitialized field value i2. Calling trace:

Diff for: tests/init-global/warn/unapplySeq-implicit-arg2.check renamed to tests/init-global/warn-tasty/unapplySeq-implicit-arg2.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Warning: tests/init-global/warn/unapplySeq-implicit-arg2.scala:4:9 --------------------------------------------------
1+
-- Warning: tests/init-global/warn-tasty/unapplySeq-implicit-arg2.scala:4:9 --------------------------------------------
22
4 | Some(i1 +: seqi) // warn
33
| ^^
44
|Access uninitialized field value i1. Calling trace:

Diff for: tests/init-global/warn/unapplySeq-implicit-arg3.check renamed to tests/init-global/warn-tasty/unapplySeq-implicit-arg3.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Warning: tests/init-global/warn/unapplySeq-implicit-arg3.scala:3:27 -------------------------------------------------
1+
-- Warning: tests/init-global/warn-tasty/unapplySeq-implicit-arg3.scala:3:27 -------------------------------------------
22
3 | def m(seq: Seq[Int]) = i1 +: seq // warn
33
| ^^
44
|Access uninitialized field value i1. Calling trace:

Diff for: tests/init-global/warn/widen.check

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Warning: tests/init-global/warn/widen.scala:13:13 -------------------------------------------------------------------
2+
13 | t.foo() // warn
3+
| ^^^^^^^
4+
| Value is unknown to the checker due to widening. Calling trace:
5+
| ├── object O: [ widen.scala:9 ]
6+
| │ ^
7+
| ├── val a = bar(new C) [ widen.scala:20 ]
8+
| │ ^^^^^^^^^^
9+
| ├── def bar(t: T) = { [ widen.scala:10 ]
10+
| │ ^
11+
| ├── new A [ widen.scala:18 ]
12+
| │ ^^^^^
13+
| ├── class A { [ widen.scala:11 ]
14+
| │ ^
15+
| ├── val b = new B [ widen.scala:16 ]
16+
| │ ^^^^^
17+
| ├── class B { [ widen.scala:12 ]
18+
| │ ^
19+
| └── t.foo() // warn [ widen.scala:13 ]
20+
| ^^^^^^^

Diff for: tests/init-global/warn/widen.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
trait T {
2+
def foo(): Unit
3+
}
4+
5+
class C extends T {
6+
def foo(): Unit = println("Calling foo on an instance of C!")
7+
}
8+
9+
object O:
10+
def bar(t: T) = {
11+
class A {
12+
class B {
13+
t.foo() // warn
14+
}
15+
16+
val b = new B
17+
}
18+
new A
19+
}
20+
val a = bar(new C)

0 commit comments

Comments
 (0)