Skip to content

Anonymous inferred trait parameter is an Illegal field #6124

Closed
@bishabosha

Description

@bishabosha

The JVM crashes at runtime when loading example.BadTest.Bad because the given Foo[A] is encoded as a final field on an interface that has no value, whereas with implicit evidence, or an explicit name it is encoded as a method.

package example

type Box[A] = A

trait Foo[A]

implied [A] for Foo[A]

object OkTest {
  trait Ok[A: Foo] extends Foo[Box[A]] {}
  implied [A] given Foo[A] for Ok[A]

  def test: Unit = {
    println(the[Ok[Box[Unit]]])
  }
}

object OkTest2 {
  trait Ok[A] given (f: Foo[A]) extends Foo[Box[A]] {}
  implied [A] given Foo[A] for Ok[A]

  def test: Unit = {
    println(the[Ok[Box[Unit]]])
  }
}

object BadTest {
  trait Bad[A] given Foo[A] extends Foo[Box[A]] {}
  implied [A] given Foo[A] for Bad[A]

  def test: Unit = {
    println(the[Bad[Box[Unit]]])
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions