Skip to content

TASTY: PackageDef#unapply is unsafe #8521

Closed
@pshirshov

Description

@pshirshov

The following code would fail:

  private def packageToName(tree: Tree): List[String] = {
    tree match {
      case PackageDef(name, owner) =>
        packageToName(owner) ++ List(name)
      case o =>
        List.empty
    }
  }

with exception like

Error:(19, 33) Exception occurred while executing macro expansion.
java.lang.AssertionError: NoDenotation.owner
	at dotty.tools.dotc.core.SymDenotations$NoDenotation$.owner(SymDenotations.scala:2253)
	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.PackageDef_owner(ReflectionCompilerInterface.scala:177)
	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.PackageDef_owner(ReflectionCompilerInterface.scala:177)
	at scala.tasty.Reflection$PackageDefOps$.owner(Reflection.scala:615)
	at scala.tasty.Reflection$PackageDef$.unapply(Reflection.scala:621)
	at izumi.reflect.dottyreflection.Inspector.packageToName(Inspector.scala:147)
	at izumi.reflect.dottyreflection.Inspector.packageToName(Inspector.scala:148)
	at izumi.reflect.dottyreflection.Inspector.packageToName(Inspector.scala:148)
	at izumi.reflect.dottyreflection.Inspector.inspectSymbol(Inspector.scala:135)
	at izumi.reflect.dottyreflection.Inspector.prefixOf(Inspector.scala:158)
	at izumi.reflect.dottyreflection.Inspector.inspectSymbol(Inspector.scala:127)
	at izumi.reflect.dottyreflection.Inspector.inspectTree(Inspector.scala:119)
	at izumi.reflect.dottyreflection.Inspector.inspectSymbol(Inspector.scala:133)
	at izumi.reflect.dottyreflection.Inspector.prefixOf(Inspector.scala:158)
	at izumi.reflect.dottyreflection.Inspector.inspectSymbol(Inspector.scala:127)
	at izumi.reflect.dottyreflection.Inspector.inspectTree(Inspector.scala:119)
	at izumi.reflect.dottyreflection.Inspector.buildTypeRef(Inspector.scala:33)
	at izumi.reflect.dottyreflection.TypeInspections$.apply(TypeInspections.scala:10)
	at izumi.reflect.dottyreflection.Inspect$.inspectAny(LightTypeTagMaterializer.scala:21)
    val bazTag = Inspect.inspect[Baz]

Seems like it fails on root package which has no owner.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions