From e715bf0108ffcc7510907ef3c21125f27c421f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Br=C3=BCckner?= Date: Fri, 3 Sep 2021 22:21:57 +0200 Subject: [PATCH] Allow to use more complex string expressions as assert() messages --- Sources/armory/system/Assert.hx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/armory/system/Assert.hx b/Sources/armory/system/Assert.hx index 995a6c14..22122994 100644 --- a/Sources/armory/system/Assert.hx +++ b/Sources/armory/system/Assert.hx @@ -26,7 +26,7 @@ class Assert { @see `AssertLevel` **/ - macro public static function assert(level: ExprOf, condition: ExprOf, message: String = ""): Expr { + macro public static function assert(level: ExprOf, condition: ExprOf, ?message: ExprOf): Expr { final levelVal: AssertLevel = AssertLevel.fromExpr(level); final assertThreshold = AssertLevel.fromString(Context.definedValue("arm_assert_level")); @@ -39,7 +39,7 @@ class Assert { return macro { if (!$condition) { @:pos(condition.pos) - trace(@:privateAccess armory.system.Assert.ArmAssertionException.formatMessage($v{condition.toString()}, $v{message})); + trace(@:privateAccess armory.system.Assert.ArmAssertionException.formatMessage($v{condition.toString()}, ${message})); } } case Error: @@ -48,7 +48,7 @@ class Assert { #if arm_assert_quit kha.System.stop(); #end @:pos(condition.pos) - @:privateAccess throwAssertionError($v{condition.toString()}, $v{message}); + @:privateAccess throwAssertionError($v{condition.toString()}, ${message}); } } default: @@ -74,14 +74,14 @@ class ArmAssertionException extends PosException { /** @param exprString The string representation of the failed assert condition. - @param message Custom error message, use an empty string to omit this. + @param message Custom error message, use `null` to omit this. **/ - public inline function new(exprString: String, message: String, ?previous: Exception, ?pos: Null) { + public inline function new(exprString: String, message: Null, ?previous: Exception, ?pos: Null) { super('\n${formatMessage(exprString, message)}', previous, pos); } - static inline function formatMessage(exprString: String, message: String): String { - final optMsg = message != "" ? '\n\tMessage: $message' : ""; + static inline function formatMessage(exprString: String, message: Null): String { + final optMsg = message != null ? '\n\tMessage: $message' : ""; return 'Failed assertion:$optMsg\n\tExpression: ($exprString)'; }