@@ -1778,13 +1778,34 @@ open class KotlinFileExtractor(
17781778 return
17791779 }
17801780
1781- val func = (( c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner as ? IrClass )?.declarations?.findSubType< IrFunction > { it.name.asString() == fnName }
1782- if (func == null ) {
1783- logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1781+ val enumType = (c.getTypeArgument(0 ) as ? IrSimpleType )?.classifier?.owner
1782+ if (enumType == null ) {
1783+ logger.errorElement(" Couldn't find type of enum type" , c)
17841784 return
17851785 }
17861786
1787- extractMethodAccess(func, false )
1787+ if (enumType is IrClass ) {
1788+ val func = enumType.declarations.findSubType<IrFunction > { it.name.asString() == fnName }
1789+ if (func == null ) {
1790+ logger.errorElement(" Couldn't find function $fnName on enum type" , c)
1791+ return
1792+ }
1793+
1794+ extractMethodAccess(func, false )
1795+ } else if (enumType is IrTypeParameter && enumType.isReified) {
1796+ // A call to `enumValues<T>()` is being extracted, where `T` is a reified type parameter of an `inline` function.
1797+ // We can't generate a valid expression here, because we would need to know the type of T on the call site.
1798+ val id = tw.getFreshIdLabel<DbErrorexpr >()
1799+ val type = useType(c.type)
1800+
1801+ tw.writeExprs_errorexpr(id, type.javaResult.id, parent, idx)
1802+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
1803+ tw.writeHasLocation(id, tw.getLocation(c))
1804+ tw.writeCallableEnclosingExpr(id, callable)
1805+ tw.writeStatementEnclosingExpr(id, enclosingStmt)
1806+ } else {
1807+ logger.errorElement(" Unexpected enum type rep ${enumType.javaClass} " , c)
1808+ }
17881809 }
17891810
17901811 fun binopReceiver (id : Label <out DbExpr >, receiver : IrExpression ? , receiverDescription : String ) {
0 commit comments