Skip to content
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

Single abstract method (SAM) composes poorly with Product type #21777

Open
tribbloid opened this issue Oct 16, 2024 · 0 comments
Open

Single abstract method (SAM) composes poorly with Product type #21777

tribbloid opened this issue Oct 16, 2024 · 0 comments

Comments

@tribbloid
Copy link

Compiler version

3.5.1

Minimized code

In the following code, e1, e2, e3 should be equivalent

object ProductSAM {

  trait Example extends Product {

    def apply(v: Int): String

    override def canEqual(that: Any): Boolean = that.isInstanceOf[Example]

  }

  object e0 extends Example {
    override def apply(v: Int): String = v.toString
  }

  val e1: Example = new Example {
    override def apply(v: Int): String = v.toString
  }

  val e2: Example = { (v: Int) =>
    v.toString
  }
}

Output

e3 is the only definition that triggered the following error:

Found:    Int => String
Required: com.tribbloids.spike.dotty.ProductSAM.Example

Explanation
===========

Tree: {
  def $anonfun(v: Int): String =
    {
      v.toString()
    }
  closure($anonfun)
}
I tried to show that
  Int => String
conforms to
  com.tribbloids.spike.dotty.ProductSAM.Example
but none of the attempts shown below succeeded:

  ==> Int => String  <:  com.tribbloids.spike.dotty.ProductSAM.Example class dotty.tools.dotc.core.Types$CachedAppliedType class dotty.tools.dotc.core.Types$CachedTypeRef  = false

The tests were made under the empty constraint

  val e2: Example = { (v: Int) =>

Expectation

the definition of e3 should work with both Scala 2/3 syntax (right now it breaks in both)

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2024
@Gedochao Gedochao added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 16, 2024
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

2 participants