Skip to content

Commit 842919a

Browse files
authored
Merge pull request #10818 from dotty-staging/fix-#10817
Fix #10817: Harden CheckStatic
2 parents 8acc1cb + 1d612cb commit 842919a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CheckStatic extends MiniPhase {
3636
if (defn.symbol.isScalaStatic) {
3737
if (!ctx.owner.is(Module))
3838
report.error(StaticFieldsOnlyAllowedInObjects(defn.symbol), defn.srcPos)
39+
defn.symbol.resetFlag(JavaStatic)
3940

4041
if (defn.isInstanceOf[ValDef] && hadNonStaticField)
4142
report.error(StaticFieldsShouldPrecedeNonStatic(defn.symbol, defns), defn.srcPos)
@@ -68,6 +69,7 @@ class CheckStatic extends MiniPhase {
6869
case t: Select => isSafeQual(t.qualifier) && symbolWhitelist.contains(t.symbol)
6970
case t: Ident => symbolWhitelist.contains(t.symbol)
7071
case t: Block => t.stats.forall(tpd.isPureExpr) && isSafeQual(t.expr)
72+
case _ => false
7173
}
7274
if (isSafeQual(tree.qualifier))
7375
ref(tree.symbol)

tests/neg/i10817.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import annotation.static
2+
3+
class T:
4+
@static val foo = 10 // error
5+
6+
val x = (new T).foo

0 commit comments

Comments
 (0)