Skip to content

Commit

Permalink
Set default values for calls to new in reactivator flow
Browse files Browse the repository at this point in the history
  • Loading branch information
aziemchawdhary-gs committed Jun 4, 2024
1 parent 3095afc commit eb7ef19
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,22 @@ public void testReactivateFunctionExpressionWithPackageArg()
"}\n");
Assert.assertEquals(runtime.getCoreInstance("test::pkg1"), ((InstanceValue) execute("test::pkg1::test():Any[1]"))._values().getOnly());
}

@Test
public void testReactivateNewDefaultValues()
{
compileTestSource("testSource.pure",
"Class test::A\n" +
"{\n" +
" a:Boolean[1] = true;\n" +
"}\n" +
"\n" +
"function test::f():Boolean[1]\n" +
"{\n" +
" let l = {| ^test::A()};\n" +
" let a = $l.expressionSequence->evaluateAndDeactivate()->toOne()->reactivate()->cast(@test::A)->toOne();\n" +
" assert($a.a, | '');\n" +
"}\n");
execute("test::f():Boolean[1]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.FunctionDefinition;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunction;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.NativeFunction;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.DefaultValue;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.Property;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.property.QualifiedProperty;
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity;
Expand Down Expand Up @@ -731,9 +732,34 @@ public void safeValue(KeyExpression o) throws Exception
{
m.invoke(result, Lists.fixedSize.of(res));
}

}
});

// Set default values
aClass._properties().forEach(new CheckedProcedure<Property<?, ?>>()
{
@Override
public void safeValue(Property<?, ?> p) throws Exception
{
DefaultValue defaultValue = p._defaultValue();
if (defaultValue != null)
{
Object result = reactivate(defaultValue._functionDefinition()._expressionSequence().getFirst(), new PureMap(Maps.fixedSize.empty()), bridge, es);
Method method = c.getMethod("_" + p._name(), RichIterable.class);
if (result instanceof RichIterable)
{
method.invoke(result, result);
}
else
{
method.invoke(result, Lists.fixedSize.of(result));
}
}
}
});


return result;
}
catch (RuntimeException e)
Expand Down

0 comments on commit eb7ef19

Please sign in to comment.