diff --git a/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala b/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala index ee6a41d86bd9..dc931813b1f9 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala @@ -36,6 +36,7 @@ class CheckStatic extends MiniPhase { if (defn.symbol.isScalaStatic) { if (!ctx.owner.is(Module)) report.error(StaticFieldsOnlyAllowedInObjects(defn.symbol), defn.srcPos) + defn.symbol.resetFlag(JavaStatic) if (defn.isInstanceOf[ValDef] && hadNonStaticField) report.error(StaticFieldsShouldPrecedeNonStatic(defn.symbol, defns), defn.srcPos) @@ -68,6 +69,7 @@ class CheckStatic extends MiniPhase { case t: Select => isSafeQual(t.qualifier) && symbolWhitelist.contains(t.symbol) case t: Ident => symbolWhitelist.contains(t.symbol) case t: Block => t.stats.forall(tpd.isPureExpr) && isSafeQual(t.expr) + case _ => false } if (isSafeQual(tree.qualifier)) ref(tree.symbol) diff --git a/tests/neg/i10817.scala b/tests/neg/i10817.scala new file mode 100644 index 000000000000..c9388274fc25 --- /dev/null +++ b/tests/neg/i10817.scala @@ -0,0 +1,6 @@ +import annotation.static + +class T: + @static val foo = 10 // error + +val x = (new T).foo \ No newline at end of file