Skip to content

java.lang.AssertionError in compiler with SAM traits with given parameters #7980

Closed
@RianGoossens

Description

@RianGoossens

minimized code

trait Evidence[X]

trait Trait[X : Evidence]
  def method(x : X) : X

given ev : Evidence[Int] = new Evidence[Int]{}
val crash : Trait[Int] = (x: Int) => x
Compilation output
java.lang.AssertionError: assertion failed: missing parameters for trait Trait from () extends Object(), Trait {
  final def method(x: Int): Int = $anonfun(x)
  final def method(x: Object): Object =
    scala.Int.box(this.method(scala.Int.unbox(x)))
} should have been caught in typer while compiling <my scala file>

expectation

I think either:

  • This should give a proper compiler error, forcing the user to write
val noCrash : Trait[Int] = new Trait[Int] with 
  def method(x: Int) = x

which does compile succesfully.

  • This should work if the evidence is in scope, altough this would force you to use summon
  • The SAM functionality could be adapted to support given parameters in the trait. In this case I think it would make a lot of sense if the following example would work:
val noCrash : Trait[Int] = (given Evidence[Int]) => (x: Int) => x

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions