Skip to content

Incorrect infering "Nothing" as a type argument of fun in 'Unapply' #175

Closed
@DarkDimius

Description

@DarkDimius
object test {
  class Foo[a](val arg : a)

  object Foo  {
    def unapply [a](m : Foo[a]) = Some (m.arg)
  }
  def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }}
// Unapply node here will have type argument [a] instantiated to scala.Nothing:
// UnApply(TypeApply(Select(Ident(Foo),unapply),List(TypeTree[TypeVar(PolyParam(a) -> TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing))])),List(),List(Bind(x,Ident(_))))
// but the type of the UnApply node itself is correct: RefinedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),test$)),Foo), test$$Foo$$a, TypeAlias(TypeRef(NoPrefix,a)))
}

Given such types the rewriting from UnApply(fun,Nil,_) to
val result = fun(matchSelector) cannot be applied as sel has type not matching fun(because fun was instantiated with wrong type arguments)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions