Skip to content

Commit 826e5ab

Browse files
committed
Implement @static sip.
This pull request implements most of machinery needed for scala/docs.scala-lang#491 Only 3-rd check is not implemented by this commit. I propose to get this in faster to fix scala#1149
1 parent a509267 commit 826e5ab

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ class DottyBackendInterface(outputDirectory: AbstractFile)(implicit ctx: Context
601601
isPrivate //|| (sym.isPrimaryConstructor && sym.owner.isTopLevelModuleClass)
602602

603603
def isFinal: Boolean = sym is Flags.Final
604-
def isStaticMember: Boolean = (sym ne NoSymbol) && ((sym is Flags.JavaStatic) || (owner is Flags.ImplClass))
604+
def isStaticMember: Boolean = (sym ne NoSymbol) &&
605+
((sym is Flags.JavaStatic) || (owner is Flags.ImplClass) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot))
605606
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
606607

607608
def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass)

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Compiler {
4444
List(new FirstTransform,
4545
new CheckReentrant),
4646
List(new RefChecks,
47+
new CheckStatic,
4748
new ElimRepeated,
4849
new NormalizeFlags,
4950
new ExtensionMethods,

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
320320
case _ =>
321321
false
322322
}
323-
try test || tp.symbol.is(JavaStatic)
323+
try test || tp.symbol.is(JavaStatic) || tp.symbol.hasAnnotation(defn.ScalaStaticAnnot)
324324
catch { // See remark in SymDenotations#accessWithin
325325
case ex: NotDefinedHere => test(ctx.addMode(Mode.FutureDefsOK))
326326
}
@@ -337,6 +337,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
337337
else if (prefixIsElidable(tp)) Ident(tp)
338338
else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
339339
followOuterLinks(This(tp.symbol.moduleClass.asClass))
340+
else if (tp.symbol hasAnnotation defn.ScalaStaticAnnot)
341+
Ident(tp)
340342
else tp.prefix match {
341343
case pre: SingletonType => followOuterLinks(singleton(pre)).select(tp)
342344
case pre => SelectFromTypeTree(TypeTree(pre), tp)

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ class Definitions {
462462
def ScalaLongSignatureAnnot(implicit ctx: Context) = ScalaLongSignatureAnnotType.symbol.asClass
463463
lazy val ScalaStrictFPAnnotType = ctx.requiredClassRef("scala.annotation.strictfp")
464464
def ScalaStrictFPAnnot(implicit ctx: Context) = ScalaStrictFPAnnotType.symbol.asClass
465+
lazy val ScalaStaticAnnotType = ctx.requiredClassRef("scala.annotation.static")
466+
def ScalaStaticAnnot(implicit ctx: Context) = ScalaStaticAnnotType.symbol.asClass
465467
lazy val SerialVersionUIDAnnotType = ctx.requiredClassRef("scala.SerialVersionUID")
466468
def SerialVersionUIDAnnot(implicit ctx: Context) = SerialVersionUIDAnnotType.symbol.asClass
467469
lazy val TASTYSignatureAnnotType = ctx.requiredClassRef("scala.annotation.internal.TASTYSignature")

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ object SymDenotations {
285285
final def addAnnotation(annot: Annotation): Unit =
286286
annotations = annot :: myAnnotations
287287

288+
/** Add given annotation to the annotations of this denotation */
289+
final def addAnnotation(annot: ClassSymbol)(implicit ctx: Context): Unit =
290+
addAnnotation(ConcreteAnnotation(tpd.ref(annot)))
291+
288292
/** Remove annotation with given class from this denotation */
289293
final def removeAnnotation(cls: Symbol)(implicit ctx: Context): Unit =
290294
annotations = myAnnotations.filterNot(_ matches cls)

src/scala/annotation/static.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package scala.annotation
2+
3+
import scala.annotation.meta._
4+
5+
/** https://github.com/scala/scala.github.com/pull/491 */
6+
7+
@field
8+
@getter
9+
@beanGetter
10+
@beanGetter
11+
@param
12+
@setter
13+
final class static extends StaticAnnotation

0 commit comments

Comments
 (0)