Skip to content

Imprecise type inference on pattern #4816

Closed
@Medowhill

Description

@Medowhill
import annotation.unchecked.uncheckedVariance

abstract class Type {
  def dealias: Type
}

object Trees {
  abstract class Tree[-T >: Null] {
    def tpe: T @uncheckedVariance = ???
  }

  case class AppliedTypeTree[-T >: Null]() extends Tree[T]
}

abstract class Instance[T >: Null <: Type] {
  type Tree = Trees.Tree[T]
  type AppliedTypeTree = Trees.AppliedTypeTree[T]
}

object untpd extends Instance[Null] {
  case class TypedSplice(tree: tpd.Tree) extends Tree

  def New(tpt: Tree): Type = tpt match {
    case TypedSplice(tpt1: AppliedTypeTree) => tpt1.tpe.dealias
    case _ => ???
  }
}

object tpd extends Instance[Type]

When I compiled the above code by scalac, it succeeded. However, when I used dotc, it failed with the following error message:

-- [E008] Member Not Found Error: Test.scala:24:56 -----------------------------
24 |    case TypedSplice(tpt1: AppliedTypeTree) => tpt1.tpe.dealias
   |                                               ^^^^^^^^^^^^^^^^
   |              value `dealias` is not a member of Null @uncheckedVariance
one error found

When I changed tpt1: AppliedTypeTree into tpt1: tpd.AppliedTypeTree in line 24, it was compiled successfully on both scalac and dotc.
Changing tpt1: AppliedTypeTree into tpt1 @ Trees.AppliedTypeTree() also worked.

I found this issue while working on issue #4557. Related PR can be found at #4798.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions