From a3ac776907c6203984bcdea4d54e68541cf1cb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sat, 25 Nov 2023 14:47:55 +0300 Subject: [PATCH] return type errors in places previously missed --- classes/types/deck_type.gd | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/classes/types/deck_type.gd b/classes/types/deck_type.gd index d666dfd..f011c1a 100644 --- a/classes/types/deck_type.gd +++ b/classes/types/deck_type.gd @@ -19,7 +19,7 @@ func set_value(new_value: Variant) -> void: ## Virtual function. Used to convert [param other] to the overriding class' type. -static func from(other: DeckType): +static func from(other: DeckType) -> DeckType: return null @@ -53,7 +53,7 @@ class DeckTypeNumeric extends DeckType: ## [code]0.0[/code] for [code]false[/code].[br] ## In the case of [DeckType.DeckTypeString], converts to String if it is a valid number ## or [DeckType.DeckTypeError] otherwise. - static func from(other: DeckType): + static func from(other: DeckType) -> DeckType: if other is DeckTypeNumeric: return other @@ -74,7 +74,7 @@ class DeckTypeNumeric extends DeckType: return inst var err: DeckTypeError = DeckTypeError.from(other) - err.error_message = "Conversion to Numeric is only possible from String or Bool." + err.error_message = "Conversion to Numeric is only possible from String or Bool" return err @@ -84,12 +84,13 @@ class DeckTypeString extends DeckType: _value = value - static func from(other: DeckType): + static func from(other: DeckType) -> DeckTypeString: if other is DeckTypeString: return other var inst := DeckTypeString.new() inst._value = var_to_str(other.get_value()) + return inst ## Boolean type. Corresponds to the JSON bool type. @@ -103,7 +104,7 @@ class DeckTypeBool extends DeckType: ## if the value is a zero value ([code]0.0[/code] and [code]-0.0[/code]), [code]true[/code] otherwise.[br] ## In the case of [DeckType.DeckTypeDictionary] or [DeckType.DeckTypeArray], ## the resulting value will be [code]true[/code] if the container is not empty. - static func from(other: DeckType): + static func from(other: DeckType) -> DeckType: if other is DeckTypeBool: return other @@ -117,6 +118,10 @@ class DeckTypeBool extends DeckType: inst._value = !other.get_value().is_empty() return inst + var err := DeckTypeError.from(other) + err.error_message = "Cannot create a DeckTypeBool from non-numeric or non-container type" + return err + ## Array type. Corresponds to the JSON Array type. class DeckTypeArray extends DeckType: @@ -126,14 +131,14 @@ class DeckTypeArray extends DeckType: ## Arrays can only be converted from a string in the format ## [code]"["foo", 2, "bar"][/code]. - static func from(other: DeckType): + static func from(other: DeckType) -> DeckType: if other is DeckTypeString: var inst := DeckTypeArray.new() inst._value = str_to_var(other.get_value()) return inst var err: DeckTypeError = DeckTypeError.from(other) - err.error_message = "conversions to Array is only possible from String" + err.error_message = "Conversions to Array is only possible from String" return err @@ -145,7 +150,7 @@ class DeckTypeDictionary extends DeckType: ## Dictionaries can only be converted from a string in the format ## [code]{"key": "value"}[/code]. - static func from(other: DeckType): + static func from(other: DeckType) -> DeckType: if other is DeckTypeString: var inst := DeckTypeDictionary.new() inst._value = str_to_var(other.get_value())