Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RianGoossens opened this issue Jan 13, 2020 · 0 comments · Fixed by #7983
Closed

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

RianGoossens opened this issue Jan 13, 2020 · 0 comments · Fixed by #7983
Assignees

Comments

@RianGoossens
Copy link

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
@liufengyun liufengyun self-assigned this Jan 14, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2020
nicolasstucki added a commit that referenced this issue Jan 14, 2020
Fix #7980: SAM type should check trait parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants