bug icon indicating copy to clipboard operation
bug copied to clipboard

tasty reader, selection of top level definition from package does not work in an annotation

Open bishabosha opened this issue 3 years ago • 3 comments

originally found in https://github.com/typelevel/cats/issues/4304

Reproduction steps

Scala version: 2.13.9

//> using scala "2.13.9"
//> using options "-Ytasty-reader", "-Ydebug-tasty"
//> using lib "org.typelevel:cats-core_3:2.8.0"

import cats.syntax.all._

object Main extends App

Problem

this code makes the error

./bar.scala:7:21: can't find type required by method catsInstancesForIdCompat2_6_1 in object cats.Invariant: compat.targetName; perhaps it is missing from the classpath.

The cause? annotations of the Invariant.catsInstancesForIdCompat2_6_1 method get forced, one of them being @cats.compat.targetName(...).

targetName is a type alias defined in cats.compat.compat$package but it seems that is never looked at because top level definition wrappers are not considered as part of the package scope in scala 2.

in the -Ydebug-tasty trace, we see that tasty reader tries to force the cats.compat.package package object which is of course empty.

#[6266, Invariant]: [8) <<< forcing annotations of symbol: `(#11713) method catsInstancesForIdCompat2_6_1`
#[6266, Invariant]: [8 0) <<< read within owner: `(#11713) method catsInstancesForIdCompat2_6_1` with modes `ReadAnnotation | ReadAnnotationCtor` at Addr(1118)
#[6266, Invariant]: [8 0 0) <<< reading annotation tree: `(#1738) class targetName` at Addr(1118)
#[6266, Invariant]: [8 0 0 0) <<< force symbol info: `(#7525) package class compat` in context `(#11713) method catsInstancesForIdCompat2_6_1` [space,deep]
#[6266, Invariant]: [8 0 0 0) >>> `(#7525) package class compat` was forced [space,deep]
[error] ./bar.scala:7:21: can't find type required by method catsInstancesForIdCompat2_6_1 in object cats.Invariant: compat.targetName; perhaps it is missing from the classpath.
[error] object Main extends App
[error]                     ^
Error compiling project (Scala 2.13.9, JVM)
Compilation failed

bishabosha avatar Sep 20 '22 12:09 bishabosha

@bishabosha if you want to get a fix into 2.13.10, you might need to prepare one soon, since bug 12650 may force us to do 2.13.10 promptly

SethTisue avatar Sep 23 '22 18:09 SethTisue

this is more complicated to "fix" because there is also no support for targetName either - so fixing this resolution error will still have the incorrect method call at runtime - but if the method is not used directly from scala 2 then fine

bishabosha avatar Sep 26 '22 12:09 bishabosha

@sjrd opinion is that top level definitions are too complex to put effort to support, in https://github.com/typelevel/cats/issues/4304 I suggest to move cats.compat.targetName to a normal package object, then it is an open question of can we implement support for targetName annotation.

bishabosha avatar Oct 04 '22 08:10 bishabosha

@bishabosha shall we "Backlog" this, then, or did you want to make an attempt for 2.13.11? I'll assume Backlog, but we can flip it back.

SethTisue avatar Feb 20 '23 20:02 SethTisue

Backlog is fine

bishabosha avatar Feb 21 '23 09:02 bishabosha