scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Make sure symbols in annotation trees are fresh before pickling #22002

Open mbovel opened 1 day ago

mbovel commented 1 day ago

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 https://github.com/scala/scala3/pull/19957#discussion_r1644920020 and https://github.com/scala/scala3/pull/19957#discussion_r1644921716 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 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.

mbovel commented 19 hours ago

Fixed ✅

Minimized failing test:

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) = ???
    }
}