Skip to content
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

Scala2 / 3 handles type argument differently #12953

Closed
exoego opened this issue Jun 26, 2021 · 5 comments · Fixed by #12980
Closed

Scala2 / 3 handles type argument differently #12953

exoego opened this issue Jun 26, 2021 · 5 comments · Fixed by #12980
Milestone

Comments

@exoego
Copy link

exoego commented Jun 26, 2021

Compiler version

3.0.1.RC-2

Minimized code

class Schema(impl: Class[_]) extends scala.annotation.StaticAnnotation

case class Foo[A](@Schema(classOf[List[A]]) foo: String)

Output

[error] 31 |    case class Foo[A](@Schema(classOf[List[A]]) foo: String)
[error]    |                                           ^
[error]    |                              Not found: type A

Expectation

It should compile, since it does on Scala 2.13.6.

@odersky
Copy link
Contributor

odersky commented Jun 29, 2021

It works for me without error.

@odersky odersky closed this as completed Jun 29, 2021
@prolativ
Copy link
Contributor

@odersky I tried it and it doesn't work for me either

@prolativ prolativ reopened this Jun 29, 2021
@prolativ
Copy link
Contributor

I tested this with the latest master

@odersky
Copy link
Contributor

odersky commented Jun 29, 2021

I had a stray A on my classpath. That's why it compiled for me.

@odersky
Copy link
Contributor

odersky commented Jun 29, 2021

So, yes, that's right now simply not supported. Here's what it says for the method that computes the context to be used for an annotation

  /** The context to be used for an annotation of `mdef`.
   *  This should be the context enclosing `mdef`, or if `mdef` defines a parameter
   *  the context enclosing the owner of `mdef`.
   *  Furthermore, we need to evaluate annotation arguments in an expression context,
   *  since classes defined in a such arguments should not be entered into the
   *  enclosing class.
   */
  def annotContext(mdef: untpd.Tree, sym: Symbol)(using Context): Context = {
    def isInner(owner: Symbol) = owner == sym || sym.is(Param) && owner == sym.owner
    val outer = ctx.outersIterator.dropWhile(c => isInner(c.owner)).next()
    outer.property(ExprOwner) match {
      case Some(exprOwner) if outer.owner.isClass => outer.exprContext(mdef, exprOwner)
      case _ => outer
    }
  }

It will take some effort to change this

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.

4 participants