Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run CheckStatic after UncacheGivenAliases #19318

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading