Skip to content

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

Open
@bishabosha

Description

@bishabosha

originally found in typelevel/cats#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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions