question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scala2 / 3 handles type argument differently

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oderskycommented, Jun 29, 2021

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

0reactions
oderskycommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to define "type disjunction" (union types)? - Stack Overflow
Scala handles overloading differently and, it must be admitted, somewhat less elegantly than you describe. Some of that's due to Java interoperability, some...
Read more >
Inline | Macros in Scala 3
Our example method logged uses three different kinds of parameters, illustrating that inlining handles those parameters differently: By-value parameters.
Read more >
4. Pattern Matching - Programming Scala, 2nd Edition [Book]
With Scala's pattern matching, your cases can include types, wildcards, ... Finally, sometimes we want to handle several different matches with the same...
Read more >
Scala 3 macros tips & tricks - SoftwareMill
Some of the things we've learned when implementing a number of macros using Scala 3. A handy guide to start metaprogramming with Scala....
Read more >
Overloading Resolution + Vararg methods: example should ...
There's an issue somewhere with the example with a type parameter. ... scala> def f(x: Object) = 0 f: (x: Object)Int scala> f(1,2,3)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found