Skip to content

Path-dependent type on singleton value emits spurious outer test warnings #12398

@neko-kai

Description

@neko-kai

reproduction steps

using Scala 2.13.6,

object AnnotationTools {
  def getAllTypeAnnotations(u: Universe)(typ: u.Type): List[u.Annotation] = {
    typ.finalResultType.dealias match {
      case t: u.AnnotatedTypeApi =>
        t.annotations
      case _ =>
        Nil
    }
  }
}

problem

Results in a warning:

/izumi/fundamentals/fundamentals-reflection/src/main/scala/izumi/fundamentals/reflection/AnnotationTools.scala:16:12
The outer reference in this type test cannot be checked at run time.
      case t: u.AnnotatedTypeApi =>

When decompiled, the warning is true, the outer reference is in fact not checked:

   public List getAllTypeAnnotations(final Universe u, final TypeApi typ) {
      TypeApi var6 = .MODULE$.stripByName(u, typ.finalResultType().dealias());
      Object var3;
      if (var6 instanceof AnnotatedTypeApi && true) {
         var3 = ((AnnotatedTypeApi)var6).annotations();
      } else {
         var3 = scala.package..MODULE$.Nil();
      }

      return (List)var3;
   }

However, since u. is a literal prefix of AnnotatedTypeApi, is it not supposed to be checkable at runtime?

clarification

I've submitted this report assuming the new warning in 2.13.6 was incorrect and the type prefix was checked. On decompiling I found the warning is correct, and the behavior of all previous Scala versions was incorrect – they did not check the prefix AND did not issue the warning. So I rewrote the report to complain about lack of runtime type prefix comparison; 🤦
I am not sure if the behavior is incorrect, although from a language perspective it would seem that the implementation should always be able to compare prefixes when they are present syntactically in the type.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions