Fix compiler bug, fix #1136

This commit is contained in:
Him188 2021-04-04 00:00:32 +08:00
parent caf9eb06ad
commit 39f6c1680c

View File

@ -33,7 +33,9 @@ import net.mamoe.mirai.message.MessageReceipt
import net.mamoe.mirai.message.data.FileMessage
import net.mamoe.mirai.message.data.sendTo
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
import net.mamoe.mirai.utils.RemoteFile.Companion.ROOT_PATH
import java.io.File
import java.util.*
import kotlin.contracts.contract
@ -192,6 +194,9 @@ internal class RemoteFileImpl(
}
override suspend fun isFile(): Boolean = this.getFileFolderInfo().checkExists(this.path).isFile
// compiler bug
override suspend fun isDirectory(): Boolean = !isFile()
override suspend fun length(): Long = this.getFileFolderInfo().checkExists(this.path).size
override suspend fun exists(): Boolean = this.getFileFolderInfo() != null
override suspend fun getInfo(): RemoteFile.FileInfo? {
@ -254,6 +259,9 @@ internal class RemoteFileImpl(
}
}
// compiler bug
override suspend fun listFilesCollection(): List<RemoteFile> = listFiles().toList()
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@OptIn(JavaFriendlyAPI::class)
override suspend fun listFilesIterator(lazy: Boolean): Iterator<RemoteFile> {
@ -305,6 +313,9 @@ internal class RemoteFileImpl(
return getFilesFlow().filter { it.id == id }.firstOrNull()?.resolveToFile()
}
// compiler bug
override suspend fun resolveById(id: String): RemoteFile? = resolveById(id, deep = true)
override fun resolveSibling(relative: String): RemoteFileImpl {
val parent = this.parent
if (parent == null) {
@ -513,10 +524,34 @@ internal class RemoteFileImpl(
)
}
// compiler bug
override suspend fun upload(resource: ExternalResource): FileMessage {
return upload(resource, null)
}
// compiler bug
override suspend fun upload(file: File, callback: RemoteFile.ProgressionCallback?): FileMessage =
file.toExternalResource().use { upload(it, callback) }
//compiler bug
override suspend fun upload(file: File): FileMessage {
// Dear compiler:
//
// Please generate invokeinterface.
//
// Yours Sincerely
// Him188
return file.toExternalResource().use { upload(it) }
}
override suspend fun uploadAndSend(resource: ExternalResource): MessageReceipt<Contact> {
return upload(resource).sendTo(contact)
}
// compiler bug
override suspend fun uploadAndSend(file: File): MessageReceipt<Contact> =
file.toExternalResource().use { uploadAndSend(it) }
// override suspend fun writeSession(resource: ExternalResource): FileUploadSession {
// }