Skip to content

Failure to parse array annotation argument from Scala 2 dependency #14223

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

Closed
14sxlin opened this issue Jan 6, 2022 · 2 comments · Fixed by #14334
Closed

Failure to parse array annotation argument from Scala 2 dependency #14223

14sxlin opened this issue Jan 6, 2022 · 2 comments · Fixed by #14334

Comments

@14sxlin
Copy link

14sxlin commented Jan 6, 2022

I am using a scala 2.13 library Kantan ("com.nrinaudo" % "kantan.csv-commons" % "0.6.2" cross CrossVersion.for3Use2_13) in scala 3.1.0 of cross version.

When I try to provide a implicit instance the compiler crashes. (Using given has the same result.)

Did I do something wrong ? Or Any Idea? I think the library may have used some scala 2 macro so it won't compile in scala 3. If that is true , it will be better if we has more specific compile error output.

I found this may help : scalacenter/bloop#1272

Compiler version

scalaVersion: 3.1.0
sbt: 1.6.1

Minimized code

full demo: https://github.com/14sxlin/compileerror

In build.sbt

val scala3Version = "3.1.0"

lazy val root = project
  .in(file("."))
  .settings(
    name := "compileerrordemo",
    version := "0.1.0-SNAPSHOT",
    scalaVersion := scala3Version,
    libraryDependencies += "com.nrinaudo" % "kantan.csv-commons" % "0.6.2" cross CrossVersion.for3Use2_13
  )

In Main.scala

import kantan.csv.CellEncoder

@main def encode: Unit =

  implicit val cellEncoder = new CellEncoder[String] {
    override def encode(str: String): String =
      str
  }

Output

[error] Found:    Seq[scala.annotation.Annotation]
[error] Required: Array[String]
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

There is no useful info in compile output.

@smarter smarter self-assigned this Jan 6, 2022
@smarter smarter changed the title Compiled failed with confusing output Failure to parse array annotation argument from Scala 2 dependency Jan 6, 2022
@smarter
Copy link
Member

smarter commented Jan 6, 2022

The compiler trips up while unpickling the following annotation: https://github.com/nrinaudo/kantan.codecs/blob/08ccfc69c9982d3b59800b7c575c4adf00c12831/core/shared/src/main/scala/kantan/codecs/Encoder.scala#L41
The code that unpickles an annotation argument array is at https://github.com/lampepfl/dotty/blob/b4d03347e46d82cbefc9b9b88fe410a1ceac9551/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala#L971-L980 and looks weird indeed: array elements don't need to be annotations themselves, so we shouldn't create a SeqLiteral with element type Annotation.

smarter added a commit to dotty-staging/dotty that referenced this issue Jan 24, 2022
When an annotation argument is an Array, we can't know the element type
of the Array until we've applied the argument to the annotation
constructor, so we need to unpickle annotation arguments as untyped
trees and rely on resolveConstructor to type them. This is the same
logic we already use when unpickling Java classfiles since
610450f.

Fixes scala#14223.
@michelou
Copy link
Contributor

@smarter 🏆

smarter added a commit to dotty-staging/dotty that referenced this issue Jan 24, 2022
When an annotation argument is an Array, we can't know the element type
of the Array until we've applied the argument to the annotation
constructor, so we need to unpickle annotation arguments as untyped
trees and rely on resolveConstructor to type them. This is the same
logic we already use when unpickling Java classfiles since
610450f.

Fixes scala#14223.
Xavientois pushed a commit to Xavientois/dotty that referenced this issue Feb 2, 2022
When an annotation argument is an Array, we can't know the element type
of the Array until we've applied the argument to the annotation
constructor, so we need to unpickle annotation arguments as untyped
trees and rely on resolveConstructor to type them. This is the same
logic we already use when unpickling Java classfiles since
610450f.

Fixes scala#14223.
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
When an annotation argument is an Array, we can't know the element type
of the Array until we've applied the argument to the annotation
constructor, so we need to unpickle annotation arguments as untyped
trees and rely on resolveConstructor to type them. This is the same
logic we already use when unpickling Java classfiles since
610450f.

Fixes scala#14223.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants