return type errors in places previously missed

This commit is contained in:
Lera Elvoé 2023-11-25 14:47:55 +03:00
parent 0944c8e715
commit a3ac776907
No known key found for this signature in database

View file

@ -19,7 +19,7 @@ func set_value(new_value: Variant) -> void:
## Virtual function. Used to convert [param other] to the overriding class' type. ## 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 return null
@ -53,7 +53,7 @@ class DeckTypeNumeric extends DeckType:
## [code]0.0[/code] for [code]false[/code].[br] ## [code]0.0[/code] for [code]false[/code].[br]
## In the case of [DeckType.DeckTypeString], converts to String if it is a valid number ## In the case of [DeckType.DeckTypeString], converts to String if it is a valid number
## or [DeckType.DeckTypeError] otherwise. ## or [DeckType.DeckTypeError] otherwise.
static func from(other: DeckType): static func from(other: DeckType) -> DeckType:
if other is DeckTypeNumeric: if other is DeckTypeNumeric:
return other return other
@ -74,7 +74,7 @@ class DeckTypeNumeric extends DeckType:
return inst return inst
var err: DeckTypeError = DeckTypeError.from(other) 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 return err
@ -84,12 +84,13 @@ class DeckTypeString extends DeckType:
_value = value _value = value
static func from(other: DeckType): static func from(other: DeckType) -> DeckTypeString:
if other is DeckTypeString: if other is DeckTypeString:
return other return other
var inst := DeckTypeString.new() var inst := DeckTypeString.new()
inst._value = var_to_str(other.get_value()) inst._value = var_to_str(other.get_value())
return inst
## Boolean type. Corresponds to the JSON bool type. ## 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] ## 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], ## In the case of [DeckType.DeckTypeDictionary] or [DeckType.DeckTypeArray],
## the resulting value will be [code]true[/code] if the container is not empty. ## 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: if other is DeckTypeBool:
return other return other
@ -117,6 +118,10 @@ class DeckTypeBool extends DeckType:
inst._value = !other.get_value().is_empty() inst._value = !other.get_value().is_empty()
return inst 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. ## Array type. Corresponds to the JSON Array type.
class DeckTypeArray extends DeckType: class DeckTypeArray extends DeckType:
@ -126,14 +131,14 @@ class DeckTypeArray extends DeckType:
## Arrays can only be converted from a string in the format ## Arrays can only be converted from a string in the format
## [code]"["foo", 2, "bar"][/code]. ## [code]"["foo", 2, "bar"][/code].
static func from(other: DeckType): static func from(other: DeckType) -> DeckType:
if other is DeckTypeString: if other is DeckTypeString:
var inst := DeckTypeArray.new() var inst := DeckTypeArray.new()
inst._value = str_to_var(other.get_value()) inst._value = str_to_var(other.get_value())
return inst return inst
var err: DeckTypeError = DeckTypeError.from(other) 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 return err
@ -145,7 +150,7 @@ class DeckTypeDictionary extends DeckType:
## Dictionaries can only be converted from a string in the format ## Dictionaries can only be converted from a string in the format
## [code]{"key": "value"}[/code]. ## [code]{"key": "value"}[/code].
static func from(other: DeckType): static func from(other: DeckType) -> DeckType:
if other is DeckTypeString: if other is DeckTypeString:
var inst := DeckTypeDictionary.new() var inst := DeckTypeDictionary.new()
inst._value = str_to_var(other.get_value()) inst._value = str_to_var(other.get_value())