Skip to content

Commit

Permalink
capabilities: fix Get of inherited property
Browse files Browse the repository at this point in the history
Seems that we forgot to use the getValue expression
which was correctly created (apart from the negated nullable
condition)
  • Loading branch information
exyi committed Oct 10, 2024
1 parent ce95456 commit 36be2a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,17 @@ public static (LambdaExpression getter, LambdaExpression setter) CreatePropertyA
if (canUseDirectAccess && unwrappedType.IsValueType)
{
getValue = Call(typeof(Helpers), nameof(Helpers.GetStructValueDirect), new Type[] { unwrappedType }, currentControlParameter, Constant(property));
if (type.IsNullable())
if (!type.IsNullable())
getValue = Expression.Property(getValue, "Value");
}
else
{
getValue = Call(currentControlParameter, getValueMethod, Constant(property), Constant(property.IsValueInherited));
getValue = Convert(getValue, type);
}
return (
Expression.Lambda(
Expression.Convert(
Expression.Call(currentControlParameter, getValueMethod, Expression.Constant(property), Expression.Constant(false)),
type
),
getValue,
currentControlParameter
),
Expression.Lambda(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public static void SetValueOrBindingSlow<T>(DotvvmBindableObject c, DotvvmProper
public static T? GetStructValueDirect<T>(DotvvmBindableObject c, DotvvmProperty p)
where T: struct
{
// T being a struct allows us to invert the rather expensive `is IBinding` typecheck in EvalPropertyValue
// to a simpler is T check, as T is a single type checkable with a simple comparison
if (c.properties.TryGet(p, out var x))
{
if (x is null)
Expand Down
22 changes: 22 additions & 0 deletions src/Tests/Runtime/CapabilityPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,28 @@ public void BitMoreComplexCapability_WeirdProperties_GetterAndSetter()
Assert.AreEqual(32, controlF2.GetValue<int>("Nullable"));
}

[TestMethod]
public void BitMoreComplexCapability_InheritedProperties()
{
var control1 = new TestControlInheritedProps();
var control2 = new TestControlInheritedProps();
control1.Children.Add(control2);

control1.NotNullable = 1;
control1.Nullable = 2;

Assert.AreEqual(1, control2.NotNullable);
Assert.AreEqual(2, control2.Nullable);

Assert.AreEqual(1, control1.GetCapability<BitMoreComplexCapability>().NotNullable);
Assert.AreEqual(2, control1.GetCapability<BitMoreComplexCapability>().Nullable);
Assert.AreEqual(1, control2.GetCapability<BitMoreComplexCapability>().NotNullable);
Assert.AreEqual(2, control2.GetCapability<BitMoreComplexCapability>().Nullable);

control2.SetCapability(new BitMoreComplexCapability { NotNullable = 3, Nullable = null });
Assert.AreEqual(3, control2.NotNullable);
Assert.AreEqual(null, control2.Nullable);
}

[DataTestMethod]
[DataRow(typeof(TestControl6))]
Expand Down

0 comments on commit 36be2a3

Please sign in to comment.