Skip to content

Commit

Permalink
Gum no longer crashes when performing math operations with values lik…
Browse files Browse the repository at this point in the history
…e XUnits

fixes #552
vchelaru committed Jan 31, 2025

Verified

This commit was signed with the committer’s verified signature.
fabiankaegy Fabian Kägy
1 parent 6e110c9 commit d708bea
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Gum/Plugins/InternalPlugins/VariableGrid/EvaluatedSyntax.cs
Original file line number Diff line number Diff line change
@@ -191,8 +191,14 @@ private static object Combine(EvaluatedSyntax leftEvaluated, EvaluatedSyntax rig

private static void GetDynamicValues(object obj1, object obj2, out dynamic dynamicValue1, out dynamic dynamicValue2)
{
var type1 = GetNumericType(obj1);
var type2 = GetNumericType(obj2);
dynamicValue1 = null;
dynamicValue2 = null;

if(!TryGetNumericType(obj1, out Type type1) || !TryGetNumericType(obj2, out Type type2))
{
return;
}


// Find the larger (wider) type to ensure proper addition
var targetType = GetWiderNumericType(type1, type2);
@@ -233,17 +239,22 @@ private static string GetSimpleTypeNameForValue(object value)
: value?.GetType().ToString();
}

static Type GetNumericType(object obj)
static bool TryGetNumericType(object obj, out Type type)
{
if (obj == null)
throw new ArgumentNullException(nameof(obj));

var type = obj.GetType();
type = obj.GetType();

if (!IsNumericType(type))
throw new ArgumentException($"Object of type {type} is not a numeric type.");
{
return false;
}
else
{
return true;
}

return type;
}

static bool IsNumericType(Type type)
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ private void AddFailureForLine(ElementSave parentElement, InstanceSave leftSideI
if (response.Succeeded && evaluatedSyntax.EvaluatedType == null)
{
response = GeneralResponse.UnsuccessfulWith(
$"The right side cannot be evaluated, are you referencing a variable that doesn't exist?");
$"The right side cannot be evaluated, are you referencing a variable that doesn't exist or mixing variable types?");
}

if (response.Succeeded && !evaluatedSyntax.CastTo(leftSideVariable.Type))

0 comments on commit d708bea

Please sign in to comment.