Skip to content

Commit 3a6bad0

Browse files
Backport "Run CheckStatic after UncacheGivenAliases" to LTS (#20807)
Backports #19318 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents ab88fbf + 1f78fa0 commit 3a6bad0

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class Compiler {
6565
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
6666
new ElimPackagePrefixes, // Eliminate references to package prefixes in Select nodes
6767
new CookComments, // Cook the comments: expand variables, doc, etc.
68-
new CheckStatic, // Check restrictions that apply to @static members
6968
new CheckLoopingImplicits, // Check that implicit defs do not call themselves in an infinite loop
7069
new BetaReduce, // Reduce closure applications
7170
new InlineVals, // Check right hand-sides of an `inline val`s
@@ -77,6 +76,7 @@ class Compiler {
7776
List(new ProtectedAccessors, // Add accessors for protected members
7877
new ExtensionMethods, // Expand methods of value classes with extension methods
7978
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases
79+
new CheckStatic, // Check restrictions that apply to @static members
8080
new ElimByName, // Map by-name parameters to functions
8181
new HoistSuperArgs, // Hoist complex arguments of supercalls to enclosing scope
8282
new ForwardDepChecks, // Check that there are no forward references to local vals

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

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class CheckStatic extends MiniPhase {
3030

3131
override def description: String = CheckStatic.description
3232

33+
override def runsAfter: Set[String] = Set(UncacheGivenAliases.name)
34+
// UncachedGivenAliases eliminates static lazy vals, which are flagged as errors here
35+
3336
override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree = {
3437
val defns = tree.body.collect{case t: ValOrDefDef => t}
3538
var hadNonStaticField = false

Diff for: tests/pos/i19304.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.annotation.static
2+
trait Foo[A]
3+
object Foo:
4+
@static val foo: Foo[String] = new {}
5+
@static given Foo[String] = foo
6+
7+
def bar =
8+
val foo: Foo[String] = new {}
9+
given Foo[String] = foo

0 commit comments

Comments
 (0)