scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

misguided type inference with explicit pt and compound types #7976

Open scabug opened 10 years ago

scabug commented 10 years ago
object Test extends App {
  trait Foo
  def foo[T](x: T): T with Foo = ???

  class C
  val c: C with Foo = foo(new C)
}

23:40 ~/Projects/Master/sandbox (master)$ s
Test.scala:6: error: type mismatch;
 found   : Test.C
 required: Test.Foo with Test.C
  val c: C with Foo = foo(new C)
                          ^
one error found

Omitting the explicit type for c or qualifying the call to foo with an explicit type argument makes the code compile.

scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-7976?orig=1 Reporter: @xeno-by Affected Versions: 2.10.3, 2.11.0-M6

SethTisue commented 6 years ago

@Blaisorblade should we close as "unlikely to progress in Scala 2"?

Blaisorblade commented 6 years ago

it looks "easy" (yeah lol), it's fixed in Dotty, but if this is hard or typer is unsupported then OK.

SethTisue commented 6 years ago

let's see if anyone else comments. if not, we can close it in the next sweep.

milessabin commented 6 years ago

I think we can make progress on inference bugs in Scala 2. I vote against closing this like this.

SethTisue commented 6 years ago

@milessabin sure, we can try not to be too trigger-happy with this this overall.

but, I'd prefer to focus on individual tickets, one at a time.

if you feel this bug in particular is both clear and actionable, can you comment with your summary of what you feel the underlying issue is and what you feel a solution might look like? because if we don't have that, the noise starts overwhelming the signal.

milessabin commented 6 years ago

I have some ongoing work on improving the solver: https://github.com/scala/scala/pull/6127. This looks like the kind of thing it might pick up.

joroKr21 commented 6 years ago

I believe this has more to do with the order in which parents of type refinements are checked for subtyping rather than the type variable solver itself. Note that with is not true intersection in Scala 2. Similar to scala/scala#6257, moving type variables to the end might help, but this might also subtly change the meaning of with.