Skip to content

Commit

Permalink
Run CheckStatic after UncacheGivenAliases (#19318)
Browse files Browse the repository at this point in the history
Fixes #19304
  • Loading branch information
nicolasstucki authored Dec 21, 2023
2 parents 0336e68 + 8718084 commit 58b8108
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Compiler {
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
new ElimPackagePrefixes, // Eliminate references to package prefixes in Select nodes
new CookComments, // Cook the comments: expand variables, doc, etc.
new CheckStatic, // Check restrictions that apply to @static members
new CheckLoopingImplicits, // Check that implicit defs do not call themselves in an infinite loop
new BetaReduce, // Reduce closure applications
new InlineVals, // Check right hand-sides of an `inline val`s
Expand All @@ -76,6 +75,7 @@ class Compiler {
List(new ProtectedAccessors, // Add accessors for protected members
new ExtensionMethods, // Expand methods of value classes with extension methods
new UncacheGivenAliases, // Avoid caching RHS of simple parameterless given aliases
new CheckStatic, // Check restrictions that apply to @static members
new ElimByName, // Map by-name parameters to functions
new HoistSuperArgs, // Hoist complex arguments of supercalls to enclosing scope
new ForwardDepChecks, // Check that there are no forward references to local vals
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/CheckStatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class CheckStatic extends MiniPhase {

override def description: String = CheckStatic.description

override def runsAfter: Set[String] = Set(UncacheGivenAliases.name)
// UncachedGivenAliases eliminates static lazy vals, which are flagged as errors here

override def transformTemplate(tree: tpd.Template)(using Context): tpd.Tree = {
val defns = tree.body.collect{case t: ValOrDefDef => t}
var hadNonStaticField = false
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i19304.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.annotation.static
trait Foo[A]
object Foo:
@static val foo: Foo[String] = new {}
@static given Foo[String] = foo

def bar =
val foo: Foo[String] = new {}
given Foo[String] = foo

0 comments on commit 58b8108

Please sign in to comment.