Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method's return type can't be inferred, Nothing is used (unsoundly) #3556

Closed
scabug opened this issue Jun 11, 2010 · 5 comments
Closed

method's return type can't be inferred, Nothing is used (unsoundly) #3556

scabug opened this issue Jun 11, 2010 · 5 comments

Comments

@scabug
Copy link

scabug commented Jun 11, 2010

trait CollectsCases[C, El, +U, +V] {
  def caseDef(xs: C): U
  def caseSeq(xs: Seq[El]): V
}

trait Id {
  type Apply[U] = U
}

trait Collects[C, El, +CaseDef[T], +CaseSel[T]] {
  type PMat[U] = CollectsCases[C, El, CaseDef[U], CaseSel[U]]
  def doMatch[U](x: C)(pmat: PMat[U]): U
}

class CollectsDefault {
  implicit def collectsDef[T] = new Collects[T, T, Id#Apply, Any] {
    def doMatch[U](x: T)(pmat: PMat[U]) = pmat.caseDef(x)
  }
}

object Collects extends CollectsDefault {
  implicit def collectsSeq[C <: Seq[_], T](implicit ev: C <:< Seq[T]) = new Collects[C, T, Any, Id#Apply] {
    def doMatch[U](x: C)(pmat: PMat[U]) = pmat.caseSeq(x)
  }
}

object Test extends Application {
  def frob[C, T](xs: C)(implicit ev: Collects[C, T, Any, Any]) /*BUG: Nothing is inferred */ = {
    val pmat = new CollectsCases[C, T, C, T]{
      def caseDef(xs: C) = xs
      def caseSeq(xs: Seq[T]) = xs.head
    }
    ev.doMatch(xs)(pmat)
  }
  println(frob(List(1, 2)))
  println(frob("not a List(1, 2)"))  
}
@scabug
Copy link
Author

scabug commented Jun 11, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3556?orig=1
Reporter: @adriaanm

@scabug
Copy link
Author

scabug commented Oct 4, 2011

@soc said:
Is this fixed?

The compiler rejects the code in 2.10.0.r25759-b20110929020424 with:

<console>:20: error: covariant type CaseDef occurs in contravariant position in type Collects.this.PMat[U] of value pmat
         def doMatch[U](x: C)(pmat: PMat[U]): U
                              ^

@scabug
Copy link
Author

scabug commented Dec 2, 2011

@soc said:
Pull request for test: scala/scala#17

@scabug
Copy link
Author

scabug commented Dec 2, 2011

@paulp said:
This isn't fixed either.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@scala scala deleted a comment from scabug Nov 21, 2019
@pabloazul
Copy link
Member

Closing for staleness and unclear status. Feel free to open if you think it's still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants