Skip to content

Compiler crash: Implicit Function types + SAM #4611

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
allanrenucci opened this issue Jun 1, 2018 · 1 comment
Closed

Compiler crash: Implicit Function types + SAM #4611

allanrenucci opened this issue Jun 1, 2018 · 1 comment

Comments

@allanrenucci
Copy link
Contributor

trait Responder[T] {
  def responseFor(value: T): implicit Request => T
}

object Responder {
  val responseResponder: Responder[Response] =
    response => response
}

class Response
class Request
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" scala.MatchError: ArrayBuffer(<SingleDenotation of type MethodType(List(value), List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Response)), AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class ImplicitFunction1),List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Request), TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Response))))>, <SingleDenotation of type MethodType(List(value), List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Response)), MethodType(List(x$0), List(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Request)), TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Response)))>) (of class scala.collection.mutable.ArrayBuffer)
	at dotty.tools.dotc.transform.ExpandSAMs.transformBlock(ExpandSAMs.scala:46)
	at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:668)
        ...

Initially reported by @jeffmay on Gitter

@jeffmay
Copy link

jeffmay commented Jun 1, 2018

Woah, nice simplification!

Also, my dotty version was 0.9.0-bin-20180529-be6ae0e-NIGHTLY and the full project (on a branch) is https://github.com/jeffmay/context-in-dotty/tree/sam-compiler-bug

allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jun 5, 2018
An abstract method definition

    def m(xs: Ts): IF

is expanded to:

    def m(xs: Ts): IF = implicit (ys: Us) => m$direct(xs)(ys)
    def m$direct(xs: Ts)(ys: Us): R

An overriding method definition

    override def m(xs: Ts): IF = implicit (ys: Us) => E

is expanded to:

    def m$direct(xs: Ts)(ys: Us): R = E
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jun 26, 2018
class and trait with a single abstract method which result type is an
implicit function type are not considered SAM types anymore. The reason
is because the abstract member desugar to mutiple ones. E.g.

```scala
trait Foo {
  def foo(): implicit Int => Int
}

// becomes
trait Foo {
  def foo(): implicit Int => Int
  def foo$direct(implicit x: Int): Int
}
```
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jul 13, 2018
class and trait with a single abstract method which result type is an
implicit function type are not considered SAM types anymore. The reason
is because the abstract member desugar to mutiple ones. E.g.

```scala
trait Foo {
  def foo(): implicit Int => Int
}

// becomes
trait Foo {
  def foo(): implicit Int => Int
  def foo$direct(implicit x: Int): Int
}
```
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2018
class and trait with a single abstract method which result type is an
implicit function type are not considered SAM types anymore. The reason
is because the abstract member desugar to mutiple ones. E.g.

```scala
trait Foo {
  def foo(): implicit Int => Int
}

// becomes
trait Foo {
  def foo(): implicit Int => Int
  def foo$direct(implicit x: Int): Int
}
```
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 3, 2018
class and trait with a single abstract method which result type is an
implicit function type are not considered SAM types anymore. The reason
is because the abstract member desugar to mutiple ones. E.g.

```scala
trait Foo {
  def foo(): implicit Int => Int
}

// becomes
trait Foo {
  def foo(): implicit Int => Int
  def foo$direct(implicit x: Int): Int
}
```
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Aug 20, 2018
class and trait with a single abstract method which result type is an
implicit function type are not considered SAM types anymore. The reason
is because the abstract member desugar to mutiple ones. E.g.

```scala
trait Foo {
  def foo(): implicit Int => Int
}

// becomes
trait Foo {
  def foo(): implicit Int => Int
  def foo$direct(implicit x: Int): Int
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants