@@ -1785,13 +1785,35 @@ open class KotlinFileExtractor(
17851785 return
17861786 }
17871787
1788- val func = (( c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.findSubType< IrFunction > { it.name.asString() == fnName }
1789- if (func == null ) {
1790- logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1788+ val enumType = (c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner
1789+ if (enumType == null ) {
1790+ logger.errorElement(" Couldn't find type of enum type" , c)
17911791 return
17921792 }
17931793
1794- extractMethodAccess(func, false )
1794+ if (enumType is IrClass ) {
1795+ val func = enumType.declarations.findSubType<IrFunction > { it.name.asString() == fnName }
1796+ if (func == null ) {
1797+ logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1798+ return
1799+ }
1800+
1801+ extractMethodAccess(func, false )
1802+ } else if (enumType is IrTypeParameter && enumType.isReified) {
1803+ // A call to `enumValues<T>()` is being extracted, where `T` is a reified type parameter of an `inline` function.
1804+ // We can't generate a valid expression here, because we would need to know the type of T on the call site.
1805+ // TODO: replace error expression with something that better shows this expression is unrepresentable.
1806+ val id = tw.getFreshIdLabel<DbErrorexpr >()
1807+ val type = useType(c.type)
1808+
1809+ tw.writeExprs_errorexpr(id, type.javaResult.id, parent, idx)
1810+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
1811+ tw.writeHasLocation(id, tw.getLocation(c))
1812+ tw.writeCallableEnclosingExpr(id, callable)
1813+ tw.writeStatementEnclosingExpr(id, enclosingStmt)
1814+ } else {
1815+ logger.errorElement(" Unexpected enum type rep ${enumType.javaClass} " , c)
1816+ }
17951817 }
17961818
17971819 fun binopReceiver (id : Label <out DbExpr >, receiver : IrExpression ? , receiverDescription : String ) {
0 commit comments