scala-newtype
scala-newtype copied to clipboard
Newtype name is always equal to "Type" in compiler errors
Hi. Newtype name is always equal to "Type" in compiler errors. Example is Either[Type, Type] where it has to be Either[UserId, UserUid]. Is it possible to get proper names?
Do you have an example? That might be caused by the Scala compiler rather than the library.
Bumping this, as we are experiencing a related issue in Tapir: https://github.com/softwaremill/tapir/issues/3835 If I understand correctly, with code generated like this:
package object types {
type WidgetId = WidgetId.Type
object WidgetId {
type Repr = Int
type Base = Any { type WidgetId$newtype }
trait Tag extends Any
type Type <: Base with Tag
def apply(x: Int): WidgetId = x.asInstanceOf[WidgetId]
implicit final class Ops$newtype(val $this$: Type) extends AnyVal {
def toInt: Int = $this$.asInstanceOf[Int]
}
}
}
the WidgetId
type is ultimately resolved as WidgetId.Type
. This results in just the type name Type
shown the compiler, as well as Tapir macros which resolve the name using typeSymbol.fullName
(see here).
Maybe the generated type could be more specific, something like
type WidgetIdType <: Base with Tag
which shouldn't affect compatibility?
type WidgetIdType <: Base with Tag
erases to Object
I think