From b8d4debfb7ac8c2879eb28ee1bbdfaae835c3e1b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 20 Aug 2017 16:17:04 -0400 Subject: [PATCH] Add support for null values --- src/main/kotlin/net/shadowfacts/ekt/EKT.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt index 3c26843..91cc022 100644 --- a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt +++ b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt @@ -234,15 +234,19 @@ _result.toString() class DataProvider { internal val map = mutableMapOf() - infix fun String.to(value: Any) { + infix fun String.to(value: Any?) { if (value is TypedValue) { map[this] = value } else { - map[this] = TypedValue(value, value::class.qualifiedName!!) + if (value == null) { + throw RuntimeException("Must provide explicit type for 'null' value") + } else { + map[this] = TypedValue(value, value::class.qualifiedName!!) + } } } - infix fun Any.asType(type: String): TypedValue { + infix fun Any?.asType(type: String): TypedValue { return TypedValue(this, type) } @@ -255,6 +259,6 @@ _result.toString() } } - data class TypedValue(val value: Any, val type: String) + data class TypedValue(val value: Any?, val type: String) } \ No newline at end of file