Skip to content

Incorrect type inference for F-bounds #11234

Closed
@liufengyun

Description

@liufengyun

Compiler version

M3

Minimized code

trait Foo[A <: Foo[A]]
trait FooCreator[A <: Foo[A]] {
  def createFoo(): A
}

trait FooWrapper {
  type A <: Foo[A]
  def foo: A
}

object FooWrapper {
  def apply[A0 <: Foo[A0]](toWrap: A0): FooWrapper { type A = A0 } = new FooWrapper {
    type A = A0
    def foo: A0 = toWrap
  }
}

def error(fooWrapper: FooWrapper, processor: [A <: Foo[A]] => A => A): FooWrapper =
  FooWrapper(processor(fooWrapper.foo))

Output

Compiler reports an error with a huge type. It's impossible to see what's wrong.

The following code compiles without any problem:

def error(fooWrapper: FooWrapper, processor: [A <: Foo[A]] => A => A): FooWrapper =
-  FooWrapper(processor(fooWrapper.foo))
+  FooWrapper[fooWrapper.A](processor(fooWrapper.foo))

Expectation

Compiles without error.

This is another issue reported in #11078. As the fix is different, thus it better to handle it in a different issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions