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

Newtype name is always equal to "Type" in compiler errors #75

Open
berserk-fan opened this issue Mar 24, 2023 · 3 comments
Open

Newtype name is always equal to "Type" in compiler errors #75

berserk-fan opened this issue Mar 24, 2023 · 3 comments

Comments

@berserk-fan
Copy link

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?

@joroKr21
Copy link
Contributor

Do you have an example? That might be caused by the Scala compiler rather than the library.

@kciesielski
Copy link

Bumping this, as we are experiencing a related issue in Tapir: softwaremill/tapir#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?

@joroKr21
Copy link
Contributor

type WidgetIdType <: Base with Tag erases to Object I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants