Skip to content

Fix #10198: Be robust against missing annotations #10212

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

Merged
merged 1 commit into from
Nov 16, 2020
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
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,12 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {

// In the Scala2 ExtractAPI phase we only extract annotations that extend
// StaticAnnotation, but in Dotty we currently pickle all annotations so we
// extract everything (except inline body annotations which are handled
// above).
s.annotations.filter(_.symbol != defn.BodyAnnot) foreach { annot =>
annots += apiAnnotation(annot)
// extract everything (except annotations missing from the classpath which
// we simply skip over, and inline body annotations which are handled above).
s.annotations.foreach { annot =>
val sym = annot.symbol
if sym.exists && sym != defn.BodyAnnot then
annots += apiAnnotation(annot)
}

annots.toList
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class A {
@JavaAnnot def foo: Int = 1
@ScalaAnnot def bar: Int = 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import java.lang.annotation.*;

public @interface JavaAnnot {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class ScalaAnnot extends scala.annotation.StaticAnnotation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class B extends A
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lazy val a = project.in(file("a"))
.settings(
Compile / classDirectory := (ThisBuild / baseDirectory).value / "a-output"
)

lazy val b = project.in(file("b"))
.settings(
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sbt._
import Keys._

object DottyInjectedPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

override val projectSettings = Seq(
scalaVersion := sys.props("plugin.scalaVersion")
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
8 changes: 8 additions & 0 deletions sbt-dotty/sbt-test/source-dependencies/missing-annot/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
> a/compile
$ mkdir b-input
# Add A to the classpath of b but not the annotations referenced by the members of A
$ copy-file a-output/A.class b-input/A.class
$ copy-file a-output/A.tasty b-input/A.tasty
# B should still be able to compile even though ExtractAPI forces the
# annotations of all inherited members.
> b/compile