From 455dba4fb5cce2f68f345b7fc3bbc46ac159572f Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Tue, 7 May 2024 18:57:54 +0200 Subject: [PATCH 1/4] Add test --- tests/init-global/warn/ScalaCheck.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/init-global/warn/ScalaCheck.scala diff --git a/tests/init-global/warn/ScalaCheck.scala b/tests/init-global/warn/ScalaCheck.scala new file mode 100644 index 000000000000..0e7036c80a8f --- /dev/null +++ b/tests/init-global/warn/ScalaCheck.scala @@ -0,0 +1,22 @@ +trait CmdLineParser: + outer => + + val a: String + + trait Opt[+T]: + val default: T + val names: Set[String] + val help: String + + trait IntOpt extends Opt[Int]: + println("outer = " + outer) + println("outer.a = " + outer.a) + +object FirstParser extends CmdLineParser: + object OptMinSuccess extends IntOpt: + val default = 100 + val names = Set("bla") + val help = "bla" + + val opts = List(OptMinSuccess) // warn + val a = "FirstParser" From fd61dfa57a3de2189e1bd879a31fe45a9d330c1a Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Tue, 7 May 2024 19:02:48 +0200 Subject: [PATCH 2/4] Remove duplicate test due to races in merge --- tests/init-global/neg/TypeCast.scala | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 tests/init-global/neg/TypeCast.scala diff --git a/tests/init-global/neg/TypeCast.scala b/tests/init-global/neg/TypeCast.scala deleted file mode 100644 index 55447e9df4e2..000000000000 --- a/tests/init-global/neg/TypeCast.scala +++ /dev/null @@ -1,18 +0,0 @@ -object A { - val f: Int = 10 - def m() = f -} -object B { - val f: Int = g() - def g(): Int = f // error -} -object C { - val a: A.type | B.type = if ??? then A else B - def cast[T](a: Any): T = a.asInstanceOf[T] - val c: A.type = cast[A.type](a) // abstraction for c is {A, B} - val d = c.f // treat as c.asInstanceOf[owner of f].f - val e = c.m() // treat as c.asInstanceOf[owner of f].m() - val c2: B.type = cast[B.type](a) - val g = c2.f // no error here -} - From 96559761995ed62f9ae11315478d563687b31f26 Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Tue, 7 May 2024 19:03:05 +0200 Subject: [PATCH 3/4] Cleanup code --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 52e90c0857ed..bfa684eef8b4 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -29,7 +29,6 @@ import scala.collection.mutable import scala.annotation.tailrec import scala.annotation.constructorOnly import dotty.tools.dotc.core.Flags.AbstractOrTrait -import Decorators.* /** Check initialization safety of static objects * From 67c68b81e0a8c7d53fcbd5011fb6918851eb394a Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Thu, 9 May 2024 06:38:41 +0200 Subject: [PATCH 4/4] Fix error line --- tests/init-global/warn/ScalaCheck.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/init-global/warn/ScalaCheck.scala b/tests/init-global/warn/ScalaCheck.scala index 0e7036c80a8f..574db37e8585 100644 --- a/tests/init-global/warn/ScalaCheck.scala +++ b/tests/init-global/warn/ScalaCheck.scala @@ -13,10 +13,10 @@ trait CmdLineParser: println("outer.a = " + outer.a) object FirstParser extends CmdLineParser: - object OptMinSuccess extends IntOpt: + object OptMinSuccess extends IntOpt: // warn val default = 100 val names = Set("bla") val help = "bla" - val opts = List(OptMinSuccess) // warn + val opts = List(OptMinSuccess) val a = "FirstParser"