scala / bug

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

Type inference fails for a class instantiation for a refined class #9775

Open scabug opened 8 years ago

scabug commented 8 years ago
scala> class Foo[T]
defined class Foo

scala> def foo[T](): Foo[T] = new Foo
foo: [T]()Foo[T]

is working, however, when we add a refinement, it doesn't:

scala> def bar[T](): Foo[T] { type U } = new Foo { type U = Int }
<console>:11: error: type mismatch;
 found   : Foo[Nothing]{type U = Int}
 required: Foo[T]{type U}
       def bar[T](): Foo[T] { type U } = new Foo { type U = Int }

as a workaround, it is needed to specify the type explicitly:

scala> def baz[T](): Foo[T] { type U } = new Foo [T] { type U = Int }
baz: [T]()Foo[T]{type U}

(this issue was found while working on #9361)

scabug commented 8 years ago

Imported From: https://issues.scala-lang.org/browse/SI-9775?orig=1 Reporter: Sarunas Valaskevicius (rakatan) Affected Versions: 2.11.7 See #9361