Browse Source

fix(expressions): add explicit type checks before casting

Add type comparison using element.type() == typeof() before calling
try_get_as() to ensure correct type matching in LotPropertyAccessor
and TypeAccessorRegistry.
Billy Barrow 1 month ago
parent
commit
1028887ad9

+ 2 - 2
src/lib/Expressions/LotPropertyAccessor.vala

@@ -89,8 +89,8 @@ namespace Invercargill.Expressions {
         public PropertyAccessor? create(Element element) {
             // Check if the element's value implements Lot
             // We need to check for Lot<Object> since we can't check for Lot<T> generically
-            Lot<Object>? lot;
-            if (element.try_get_as(out lot)) {
+            Lot? lot = null;
+            if (element.type() == typeof(Lot) && element.try_get_as(out lot)) {
                 return new LotPropertyAccessor(lot);
             }
             return null;

+ 2 - 3
src/lib/Expressions/TypeAccessorRegistry.vala

@@ -146,8 +146,8 @@ namespace Invercargill.Expressions {
             }
 
             // Fallback: Check if element directly implements PropertyAccessor
-            PropertyAccessor? accessor;
-            if (element.try_get_as(out accessor)) {
+            PropertyAccessor? accessor = null;
+            if (element.type() == typeof(PropertyAccessor) && element.try_get_as(out accessor)) {
                 return accessor;
             }
 
@@ -161,7 +161,6 @@ namespace Invercargill.Expressions {
             if (element.try_get_as(out obj)) {
                 return new ObjectPropertyAccessor(obj);
             }
-
             return null;
         }