profunktor / dorado

:trident: Generic golden testing library
Apache License 2.0
9 stars 2 forks source link

Newtypes within a companion object #4

Open gvolpe opened 4 years ago

gvolpe commented 4 years ago

This works:

@newtype case class Batman(value: java.util.UUID)
@newtype case class Robin(value: java.time.Instant)

sealed trait Yay
object Yay {
  case class Foo(x: Int, aa: Robin) extends Yay
  case class Bar(y: Batman, f: String) extends Yay
}

Check[Yay]

This doesn't:

sealed trait Yay
object Yay {
  @newtype case class Batman(value: java.util.UUID)
  @newtype case class Robin(value: java.time.Instant)

  case class Foo(x: Int, aa: Robin) extends Yay
  case class Bar(y: Batman, f: String) extends Yay
}

Check[Yay] // could not find implicit value for parameter ev: munit.golden.internal.Check.Checks[Yay]
gvolpe commented 4 years ago

More updates! This works:

import io.estatico.newtype.macros.newtype
import munit.golden.internal.Check

sealed trait Yay
object Yay {
  @newtype case class MyId(value: java.util.UUID)

  case class Foo(x: Int) extends Yay
  case class Bar(y: Yay.MyId, z: String) extends Yay
}

Check[Yay]

This doesn't:

import io.estatico.newtype.macros.newtype
import munit.golden.internal.Check

sealed trait Yay
object Yay {
  @newtype case class MyId(value: java.util.UUID)

  case class Foo(x: Int) extends Yay
  case class Bar(y: MyId, z: String) extends Yay
}

Check[Yay] // could not find implicit value for parameter ev: munit.golden.internal.Check.Checks[Yay]
gvolpe commented 4 years ago

Repro: https://scastie.scala-lang.org/D4OCnd2HQZeDLYzule2W6w

gvolpe commented 4 years ago

This works:

@newtype case class MyInt(value: Int)

sealed trait Yay
object Yay {
  type ID = MyInt.type
  case class Foo2(x: Int) extends Yay
  case class Bar2(y: ID, z: String) extends Yay
}

Check[Yay]

This doesn't:

@newtype case class MyInt(value: Int)

sealed trait Yay
object Yay {
  type ID = MyInt
  case class Foo2(x: Int) extends Yay
  case class Bar2(y: ID, z: String) extends Yay
}

Check[Yay]