Skip to content

Commit

Permalink
fixup! KTOR-7479 Use TypeInfo and typeOfOrNull in AttributeKey
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Oct 4, 2024
1 parent 55a72a6 commit 8f73aae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("unused")

Expand All @@ -22,17 +22,15 @@ import kotlin.jvm.*
* @see [io.ktor.server.response.ApplicationResponse]
*/
public suspend inline fun <reified T : Any> ApplicationCall.respond(message: T) {
// KT-42913
respond(message, runCatching { typeInfo<T>() }.getOrNull())
respond(message, typeInfo<T>())
}

/**
* Sends a [message] as a response.
* @see [io.ktor.server.response.ApplicationResponse]
*/
public suspend inline fun <reified T> ApplicationCall.respondNullable(message: T) {
// KT-42913
respond(message, runCatching { typeInfo<T>() }.getOrNull())
respond(message, typeInfo<T>())
}

/**
Expand Down
6 changes: 5 additions & 1 deletion ktor-utils/common/src/io/ktor/util/reflect/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public class TypeInfo(
if (this === other) return true
if (other !is TypeInfo) return false

return if (kotlinType != null) kotlinType == other.kotlinType else type == other.type
return if (kotlinType != null || other.kotlinType != null) {
kotlinType == other.kotlinType
} else {
type == other.type
}
}

override fun toString(): String = "TypeInfo(${kotlinType ?: type})"
Expand Down

0 comments on commit 8f73aae

Please sign in to comment.