estatico / scala-newtype

NewTypes for Scala with no runtime overhead
Apache License 2.0
540 stars 31 forks source link

Existing classes are shadowed by type aliases inside the object #74

Open Mee-Tree opened 1 year ago

Mee-Tree commented 1 year ago

Example:

case class Type(name: String)

@newtype case class Foo(value: List[Type])

val value: List[Type] = List(Type("abc"))
Foo(value)

The code does not compile due to the following error:

type mismatch;
 found   : List[Type]
 required: List[Foo.Type]

The simplest solution is to rename all type aliases to avoid the possibility of name collision (like prefixing them with $).

type $Base = ...
type $Repr = ...
type $Type = ...
type $Tag = ...

Currently, as a workaround, the user can create an alias (if changing the name isn't an option), and the code would work as expected:

type TType = Type
@newtype case class Foo(value: List[TType])