Skip to content

Commit 58b8108

Browse files
Run CheckStatic after UncacheGivenAliases (#19318)
Fixes #19304
2 parents 0336e68 + 8718084 commit 58b8108

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

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

compiler/src/dotty/tools/dotc/transform/CheckStatic.scala

Lines changed: 3 additions & 0 deletions
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

tests/pos/i19304.scala

Lines changed: 9 additions & 0 deletions
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)