Skip to content

Commit 78ea80e

Browse files
author
Jaden Peterson
committed
fixup! b69c89a Added back type information to the macros
1 parent 18c59d8 commit 78ea80e

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

macros/src/main/scala/enumeratum/compat/EnumMacros.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ object EnumMacros {
1111

1212
/** Finds any [A] in the current scope and returns an expression for a list of them
1313
*/
14-
def findValuesImpl[A: c.WeakTypeTag](c: Context): c.Tree = {
14+
def findValuesImpl[A: c.WeakTypeTag](
15+
c: Context
16+
)(implicit typeTag: c.WeakTypeTag[IndexedSeq[A]]): c.Expr[IndexedSeq[A]] = {
1517
import c.universe._
1618
val typeSymbol = weakTypeOf[A].typeSymbol
1719
validateType(c)(typeSymbol)
@@ -161,22 +163,26 @@ object EnumMacros {
161163
@SuppressWarnings(Array("org.wartremover.warts.AsInstanceOf"))
162164
private[enumeratum] def buildSeqExpr[A: c.WeakTypeTag](c: Context)(
163165
subclassSymbols: Seq[c.universe.Symbol]
164-
): c.Tree = {
166+
)(implicit typeTag: c.WeakTypeTag[IndexedSeq[A]]) = {
165167
import c.universe._
166168
val resultType = weakTypeOf[A]
167169
val indexedSeq = Ident(c.mirror.staticModule(classOf[IndexedSeq[A]].getName))
168170
if (subclassSymbols.isEmpty) {
169-
TypeApply(
170-
Select(indexedSeq, ContextUtils.termName(c)("empty")),
171-
List(TypeTree(resultType))
172-
)
173-
} else {
174-
Apply(
171+
c.Expr[IndexedSeq[A]](
175172
TypeApply(
176-
Select(indexedSeq, ContextUtils.termName(c)("apply")),
173+
Select(indexedSeq, ContextUtils.termName(c)("empty")),
177174
List(TypeTree(resultType))
178-
),
179-
subclassSymbols.map(Ident(_)).toList
175+
)
176+
)
177+
} else {
178+
c.Expr[IndexedSeq[A]](
179+
Apply(
180+
TypeApply(
181+
Select(indexedSeq, ContextUtils.termName(c)("apply")),
182+
List(TypeTree(resultType))
183+
),
184+
subclassSymbols.map(Ident(_)).toList
185+
)
180186
)
181187
}
182188
}

macros/src/main/scala/enumeratum/compat/ValueEnumMacros.scala

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ object ValueEnumMacros {
1616
*/
1717
def findIntValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
1818
c: Context
19-
): c.Tree = {
19+
)(implicit
20+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
21+
): c.Expr[IndexedSeq[ValueEntryType]] = {
2022
findValueEntriesImpl[ValueEntryType, ContextUtils.CTInt, Int](c)(identity)
2123
}
2224

@@ -26,7 +28,9 @@ object ValueEnumMacros {
2628
*/
2729
def findLongValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
2830
c: Context
29-
): c.Tree = {
31+
)(implicit
32+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
33+
): c.Expr[IndexedSeq[ValueEntryType]] = {
3034
findValueEntriesImpl[ValueEntryType, ContextUtils.CTLong, Long](c)(identity)
3135
}
3236

@@ -39,7 +43,9 @@ object ValueEnumMacros {
3943
*/
4044
def findShortValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
4145
c: Context
42-
): c.Tree = {
46+
)(implicit
47+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
48+
): c.Expr[IndexedSeq[ValueEntryType]] = {
4349
findValueEntriesImpl[ValueEntryType, ContextUtils.CTInt, Short](c)(
4450
_.toShort
4551
) // do a transform because there is no such thing as Short literals
@@ -53,7 +59,9 @@ object ValueEnumMacros {
5359
*/
5460
def findStringValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
5561
c: Context
56-
): c.Tree = {
62+
)(implicit
63+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
64+
): c.Expr[IndexedSeq[ValueEntryType]] = {
5765
findValueEntriesImpl[ValueEntryType, String, String](c)(identity)
5866
}
5967

@@ -65,7 +73,9 @@ object ValueEnumMacros {
6573
*/
6674
def findByteValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
6775
c: Context
68-
): c.Tree = {
76+
)(implicit
77+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
78+
): c.Expr[IndexedSeq[ValueEntryType]] = {
6979
findValueEntriesImpl[ValueEntryType, ContextUtils.CTInt, Byte](c)(_.toByte)
7080
}
7181

@@ -77,7 +87,9 @@ object ValueEnumMacros {
7787
*/
7888
def findCharValueEntriesImpl[ValueEntryType: c.WeakTypeTag](
7989
c: Context
80-
): c.Tree = {
90+
)(implicit
91+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
92+
): c.Expr[IndexedSeq[ValueEntryType]] = {
8193
findValueEntriesImpl[ValueEntryType, ContextUtils.CTChar, Char](c)(identity)
8294
}
8395

@@ -89,7 +101,9 @@ object ValueEnumMacros {
89101
ProcessedValue
90102
](c: Context)(
91103
processFoundValues: ValueType => ProcessedValue
92-
): c.Tree = {
104+
)(implicit
105+
typeTag: c.WeakTypeTag[IndexedSeq[ValueEntryType]]
106+
): c.Expr[IndexedSeq[ValueEntryType]] = {
93107
import c.universe._
94108
val typeSymbol = weakTypeOf[ValueEntryType].typeSymbol
95109
EnumMacros.validateType(c)(typeSymbol)

0 commit comments

Comments
 (0)