Skip to content

No TypeTag available for newtypes #58

@LMnet

Description

@LMnet

Currently, there is no way to get a TypeTag for a newtype:

@newtype case class WidgetId(toInt: Int)

val widgetId = WidgetId(5)

import scala.reflect.runtime.universe._

val tt = typeTag[WidgetId] // failed with No TypeTag available

WeakTypeTag works fine:

val wtt = weakTypeTag[WidgetId]

Also, I can get a TypeTag for the Repr type:

val repr = typeTag[WidgetId.Repr]

Looks like there is no way to get a TypeTag for the newtype in the current newtype encoding because newtype's type is abstract, but TypeTag can be summoned only for a concrete type.

About my use case: I'm using doobie and it uses TypeTags very extensively for better logging and error reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions