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

@ instance: type not found #28

Open
DmytroMitin opened this issue Aug 11, 2019 · 1 comment
Open

@ instance: type not found #28

DmytroMitin opened this issue Aug 11, 2019 · 1 comment
Labels
bug Something isn't working macros

Comments

@DmytroMitin
Copy link
Owner

DmytroMitin commented Aug 11, 2019

  import com.github.dmytromitin.auxify.macros.{aux, instance}

  /*@aux*/ @instance
  trait Compare[T1, T2] {
    type T
    type Out = (T, T)
    def apply(a: T1, b: T2): Out
  }

  object Compare {
    type Aux[T1, T2, T0] = Compare[T1, T2] { type T = T0 }
//    def instance[T1, T2, T0](f: (T1, T2) => (T0, T0)): Aux[T1, T2, T0] = new Compare[T1, T2] {
//      override type T = T0
//      override def apply(a: T1, b: T2): Out = f(a, b)
//    }

    implicit def reverseCompare[T1, T2](implicit ev: T2 => T1): Aux[T1, T2, T1] = instance((a, b) => (a, ev(b)))
    implicit def directCompare[T1, T2](implicit ev: T1 => T2): Aux[T1, T2, T2] = instance((a, b) => (ev(a), b))
  }

  def compare[T1, T2](a: T1, b: T2)(implicit cmp: Compare[T1, T2]) = (compareImpl[cmp.T] _).tupled(cmp(a, b))
  def compareImpl[T](a: T, b: T) = a == b

  case class Foo(s: String)
  case class Bar(s: String)

  implicit def foo2bar(f: Foo): Bar = Bar(f.s)

  compare(Foo("hello"), Bar("hello"))
Warning:scalac: {
  abstract trait Compare[T1, T2] extends scala.AnyRef {
    type T;
    type Out = scala.Tuple2[T, T];
    def apply(a: T1, b: T2): Out
  };
  object Compare extends scala.AnyRef {
    def <init>() = {
      super.<init>();
      ()
    };
    def instance[T1, T2, T0$macro$1](f$macro$2: _root_.scala.Function2[T1, T2, Out]): Compare[T1, T2] {
      type T = T0$macro$1
    } = {
      final class $anon extends Compare[T1, T2] {
        def <init>() = {
          super.<init>();
          ()
        };
        override type T = T0$macro$1;
        type Out = scala.Tuple2[T, T];
        override def apply(a: T1, b: T2): Out = f$macro$2(a, b)
      };
      new $anon()
    };
    type Aux[T1, T2, T0] = Compare[T1, T2] {
      type T = T0
    };
    implicit def reverseCompare[T1, T2](implicit ev: _root_.scala.Function1[T2, T1]): Aux[T1, T2, T1] = instance(((a, b) => scala.Tuple2(a, ev(b))));
    implicit def directCompare[T1, T2](implicit ev: _root_.scala.Function1[T1, T2]): Aux[T1, T2, T2] = instance(((a, b) => scala.Tuple2(ev(a), b)))
  };
  ()
}

Error:(11, 13) not found: type Out
  /*@aux*/ @instance
@DmytroMitin DmytroMitin added bug Something isn't working macros labels Aug 11, 2019
@DmytroMitin
Copy link
Owner Author

DmytroMitin commented Aug 11, 2019

def instance[T1, T2, T0$macro$1](f$macro$2: _root_.scala.Function2[T1, T2, Out]): Compare[T1, T2] {
      type T = T0$macro$1
    }

instead of

  def instance[T1, T2, T0](f: (T1, T2) => (T0, T0)): Aux[T1, T2, T0] = new Compare[T1, T2] {
    override type T = T0
    override def apply(a: T1, b: T2): Out = f(a, b)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working macros
Projects
None yet
Development

No branches or pull requests

1 participant