wvlet / airframe

Essential Building Blocks for Scala
https://wvlet.org/airframe
Apache License 2.0
631 stars 64 forks source link

Surface.methodsOf: opaque type params confusion => Objc[Any] recognized as Objc[Any][Any] #2753

Open wiltonlazary opened 1 year ago

wiltonlazary commented 1 year ago
/* 
  Found:    laz.core.lang.codec.model.Objc[Any][Any]
  Required: laz.core.lang.codec.model.Objc[Any]
*/

//
opaque type Objc[A] <: Map[String, A] =
  Map[String, A]

extension [A](self: Objc[A])
  @targetName("asMap$Objc")
  implicit inline def asMap: Map[String, A] =
    self

extension [A](self: Map[String, A])
  @targetName("asObjc$Map")
  implicit inline def asObjc: Objc[A] =
    self

object Objc {
  inline def empty[A]: Objc[A] =
    Map.empty[String, A]

  inline def apply[A](elems: (String, A)*): Objc[A] =
    Map[String, A](elems: _*)
}      
//

class ModelCodecSpec extends munit.FunSuite:
  test("ObjcTest") {
    class Local0 {
      var $$related: Objc[Any] = Objc.empty
      def related: Objc[Any] = $$related
      def related_=(x: Objc[Any]): Unit = { $$related = x }
    }

    val x1 = Surface.of[Local0]
    val x2 = Surface.methodsOf[Local0]
  }
xerial commented 8 months ago

@wiltonlazary Thanks for the detailed example. I could reproduce this issue on my end, and Surface now supports opaque type #3318, I'll take a look.