Skip to content

Commit

Permalink
Force the type of an annotation's typeSymbol beofre checking isStatic
Browse files Browse the repository at this point in the history
Before 2.13, `isStatic` is implemented by
`isNonBottomSubClass(StaticAnnotationClass)`
which forces the annotation symbol's type.

In 2.13, Java annotations are identified by flags. This check doesn't
force the info, and the flags are missing if the info is still a
`ClassfileLoader`.

This leads to spurious API changes (annotation goes missing) if the
depending if the info is already forced or not.

A fix for this will be in 2.13.7, but we should still work around it
in Zinc to make sure zinc works correctly on 2.13.0-6.
  • Loading branch information
lrytz committed Aug 11, 2021
1 parent 9ae025d commit c25d956
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,14 @@ class ExtractAPI[GlobalType <: Global](
}
implicit def compat(ann: AnnotationInfo): IsStatic = new IsStatic(ann)

// scala/bug#11679 annotations of inherited members may be absent from the compile time classpath
// so avoid calling `isNonBottomSubClass` on these stub symbols which would trigger a fatal error.
annotations.filter(ann => !isStub(ann.atp.typeSymbol) && ann.isStatic)
// `isStub` for scala/bug#11679: annotations of inherited members may be absent from the compile time
// classpath so avoid calling `isNonBottomSubClass` on these stub symbols which would trigger an error.
//
// `initialize` for sbt/zinc#998: 2.13 identifies Java annotations by flags. Up to 2.13.6, this is done
// without forcing the info of `ann.atp.typeSymbol`, flags are missing it's still a `ClassfileLoader`.
annotations.filter(
ann => !isStub(ann.atp.typeSymbol) && { ann.atp.typeSymbol.initialize; ann.isStatic }
)
}

private def isStub(sym: Symbol): Boolean = sym match {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"projects": [
{
"name": "pro",
"scalaVersion": "2.13.6"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait A {
def f: String = "b"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait A {
def f: String = "a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class B extends A
7 changes: 7 additions & 0 deletions zinc/src/sbt-test/source-dependencies/trait-local-change/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> pro/clean
> pro/compile
$ copy-file changes/A2.scala pro/A.scala
# Second compilation round, there should be no third round (we don't need to recompile B.scala)
> pro/compile
# Check that there were only two rounds of compilation
> pro/checkIterations 2

0 comments on commit c25d956

Please sign in to comment.