diff --git a/app/src/main/java/io/nekohasekai/sagernet/ktx/Utils.kt b/app/src/main/java/io/nekohasekai/sagernet/ktx/Utils.kt index 7649b5b1..9d6b9d11 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/ktx/Utils.kt +++ b/app/src/main/java/io/nekohasekai/sagernet/ktx/Utils.kt @@ -270,7 +270,7 @@ fun Continuation.tryResumeWithException(exception: Throwable) { } fun T.asMap(): MutableMap { - if (!shouldAsMap(this)) throw RuntimeException("invalid type to as map") + if (!shouldAsMap(this)) throw RuntimeException("invalid type to as map: " + javaClass.name) val map = mutableMapOf() @@ -294,7 +294,7 @@ fun T.asMap(): MutableMap { } private fun shouldAsMap(value: Any?): Boolean = when (value) { - null, is String, is Number, is Boolean, is Map<*, *> -> false + null, is String, is Number, is Boolean, is Map<*, *>, is List<*> -> false else -> true } @@ -305,11 +305,7 @@ private fun mappedValue(value: Any?): Any? = when (value) { 0 -> null // Listable - 1 -> if (shouldAsMap(value[0])) { - value.asMap() - } else { - value[0] - } + 1 -> mappedValue(value[0]) else -> { val needAsMap = shouldAsMap(value[0])