-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure symbols in annotation trees are fresh before pickling (#22002)
In a nutshell: when mapping annotated types, we can currently end up with the same symbol being declared in distinct trees, which crashes the pickler as it expects each symbol to be declared in a single place. See #19957 (comment) and #19957 (comment) for more context. This PR ensures that all symbols in annotation trees are different by creating fresh symbols for all symbols in annotation tree during `PostTyper`. In my [previous attempt](ab70f18) which was discussed on #19957, I did it in `Annotations.mapWith`. Here, it's only done once in `PostTyper`, so this is more lightweight. Fixes #17939, fixes #19846 and fixes (partially?) #20272.
- Loading branch information
Showing
6 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.annotation.Annotation | ||
class myRefined[T](f: T => Boolean) extends Annotation | ||
|
||
class Box[T](val x: T) | ||
class Box2(val x: Int) | ||
|
||
class A(a: String @myRefined((x: Int) => Box(3).x == 3)) // crash | ||
class A2(a2: String @myRefined((x: Int) => Box2(3).x == 3)) // works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dependentAnnotation | ||
|
||
class lambdaAnnot(g: () => Int) extends annotation.StaticAnnotation | ||
|
||
def f(x: Int): Int @lambdaAnnot(() => x + 1) = x | ||
|
||
@main def main = | ||
val y: Int = 5 | ||
val z = f(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class qualified[T](predicate: T => Boolean) extends annotation.StaticAnnotation | ||
|
||
class EqualPair(val x: Int, val y: Int @qualified[Int](it => it == x)) | ||
|
||
@main def main = | ||
val p = EqualPair(42, 42) | ||
val y = p.y | ||
println(42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This test checks that symbols in `BodyAnnotation` are not copied in | ||
// `transformAnnot` during `PostTyper`. | ||
|
||
package json | ||
|
||
trait Reads[A] { | ||
def reads(a: Any): A | ||
} | ||
|
||
object JsMacroImpl { | ||
inline def reads[A]: Reads[A] = | ||
new Reads[A] { self => | ||
def reads(a: Any) = ??? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import language.experimental.captureChecking | ||
|
||
trait Iterable[T] { self: Iterable[T]^ => | ||
def map[U](f: T => U): Iterable[U]^{this, f} | ||
} | ||
|
||
object Test { | ||
def assertEquals[A, B](a: A, b: B): Boolean = ??? | ||
|
||
def foo[T](level: Int, lines: Iterable[T]) = | ||
lines.map(x => x) | ||
|
||
def bar(messages: Iterable[String]) = | ||
foo(1, messages) | ||
|
||
val it: Iterable[String] = ??? | ||
val msgs = bar(it) | ||
|
||
assertEquals(msgs, msgs) | ||
} |