diff --git a/src/commonMain/kotlin/com/charleskorn/kaml/YamlInput.kt b/src/commonMain/kotlin/com/charleskorn/kaml/YamlInput.kt index 5d2a51d1..b59f8ddb 100644 --- a/src/commonMain/kotlin/com/charleskorn/kaml/YamlInput.kt +++ b/src/commonMain/kotlin/com/charleskorn/kaml/YamlInput.kt @@ -30,6 +30,7 @@ import kotlinx.serialization.descriptors.StructureKind import kotlinx.serialization.descriptors.elementNames import kotlinx.serialization.encoding.AbstractDecoder import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.encoding.CompositeDecoder.Companion.DECODE_DONE import kotlinx.serialization.encoding.CompositeDecoder.Companion.UNKNOWN_NAME import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.SerializersModuleCollector @@ -168,7 +169,7 @@ private class YamlNullInput(val nullValue: YamlNode, context: SerializersModule, override fun getCurrentLocation(): Location = nullValue.location override fun getCurrentPath(): YamlPath = nullValue.path - override fun decodeElementIndex(descriptor: SerialDescriptor): Int = 0 + override fun decodeElementIndex(descriptor: SerialDescriptor): Int = DECODE_DONE } @OptIn(ExperimentalSerializationApi::class) diff --git a/src/commonTest/kotlin/com/charleskorn/kaml/YamlReadingTest.kt b/src/commonTest/kotlin/com/charleskorn/kaml/YamlReadingTest.kt index e8e1beba..9adcff53 100644 --- a/src/commonTest/kotlin/com/charleskorn/kaml/YamlReadingTest.kt +++ b/src/commonTest/kotlin/com/charleskorn/kaml/YamlReadingTest.kt @@ -1193,6 +1193,25 @@ object YamlReadingTest : Spek({ } } + // See https://github.com/charleskorn/kaml/issues/179. + context("given some input where a tag is provided but no value is provided") { + val input = """ + ! + """.trimIndent() + + context("parsing that input") { + it("throws an appropriate exception") { + expect({ polymorphicYaml.decodeFromString(TestSealedStructure.serializer(), input) }).toThrow { + message { toBe("Property 'value' is required but it is missing.") } + line { toBe(1) } + column { toBe(1) } + propertyName { toBe("value") } + path { toBe(YamlPath.root) } + } + } + } + } + context("given some input where the value is a literal") { val input = """ ! "asdfg"