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

Type inference forgets to process some type parameters #6472

Open
scabug opened this issue Oct 3, 2012 · 4 comments
Open

Type inference forgets to process some type parameters #6472

scabug opened this issue Oct 3, 2012 · 4 comments

Comments

@scabug
Copy link

scabug commented Oct 3, 2012

Given an environment where T is not bound to some type, I can get this error message:

  Foo.scala:21: error: type mismatch;
   found   : Foo.Exp[Seq[T]]
   required: Foo.Exp[Seq[Nothing]]
    assertType[Exp[Seq[Nothing]]](v)
                                  ^

where the T in the output message is an uninferred type parameter!

The core of the offending code is:

  val empty = Const(Seq.empty)
  //...Implicit conversions to pimp map and head on Const[Seq[T]]...
  val v = empty.map(x => empty.head)
  //Not fine:
  assertType[Exp[Seq[Nothing]]](v)

See https://gist.github.com/3830228 for the complete code (I can attach it here if important).

As a consequence, in 2.10 that expression cannot be passed to this function:

def f[T: TypeTag](e: Exp[T]): T = throw new Exception()
f(empty.map(x => empty.head))
/*
Error:
Foo.scala:38: error: type parameter not specified
  f(empty.map(x => empty.head))
   ^
@scabug
Copy link
Author

scabug commented Oct 3, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6472?orig=1
Reporter: @Blaisorblade
Affected Versions: 2.9.2, 2.10.0-M7, 2.10.0

@scabug
Copy link
Author

scabug commented Oct 4, 2012

@paulp said:
Considerably reduced. The difference between g0 and g1 below is only whether the implicit conversion is called explicitly.

object Bar {
  implicit def convert[T](xs: Seq[T]) = new Bippy(xs)
  class Bippy[T](xs: Seq[T]) { def bippy = xs }

  def g0 = identity(Seq().bippy)
  def g1 = identity(convert(Seq()).bippy)
  // def g0: Seq[T] = ...
  // def g1: Seq[Nothing] = ...
}

@Blaisorblade
Copy link

@milessabin You might want to triage this; I suspect "considering more variables" might be more approachable than "changing the inferred type for variables that are already inferred".

@milessabin
Copy link

milessabin commented Mar 3, 2018

I think this is most likely a consequence of a Nothing doing double duty as "unsolved". I definitely want to take a look at that problem at some point.

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

3 participants