diff --git a/legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/tests/function/base/meta/AbstractTestReactivate.java b/legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/tests/function/base/meta/AbstractTestReactivate.java index a2393ccc1a..3c3b5962bc 100644 --- a/legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/tests/function/base/meta/AbstractTestReactivate.java +++ b/legend-pure-core/legend-pure-m3-core/src/test/java/org/finos/legend/pure/m3/tests/function/base/meta/AbstractTestReactivate.java @@ -242,4 +242,26 @@ public void testReactivateNewOverrideDefaultValues() "}\n"); execute("test::f1():Boolean[1]"); } + + @Test + public void testReactivateNewDefaultValueInheritance() + { + compileTestSource("testSource.pure", + "Class test::A\n" + + "{\n" + + " a:Boolean[1] = true;\n" + + "}\n" + + "\n" + + "Class test::B extends test::A\n" + + "{\n" + + " b:Boolean[1] = true;\n" + + "}\n" + + "function test::f():Boolean[1]\n" + + "{\n" + + " let l = {| ^test::B()};\n" + + " let b = $l.expressionSequence->evaluateAndDeactivate()->toOne()->reactivate()->cast(@test::B)->toOne();\n" + + " assert($b.a, | 'Default value for property b set to wrong value');\n" + + "}\n"); + execute("test::f():Boolean[1]"); + } } diff --git a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/Pure.java b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/Pure.java index e375aa8f71..935102bb5a 100644 --- a/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/Pure.java +++ b/legend-pure-runtime/legend-pure-runtime-java-engine-compiled/src/main/java/org/finos/legend/pure/runtime/java/compiled/generation/processors/support/Pure.java @@ -55,6 +55,7 @@ import org.finos.legend.pure.m3.navigation.Instance; import org.finos.legend.pure.m3.navigation.M3Paths; import org.finos.legend.pure.m3.navigation.ProcessorSupport; +import org.finos.legend.pure.m3.navigation._class._Class; import org.finos.legend.pure.m3.navigation.generictype.GenericType; import org.finos.legend.pure.m4.coreinstance.CoreInstance; import org.finos.legend.pure.m4.coreinstance.SourceInformation; @@ -718,23 +719,28 @@ public static Object newObject(Bridge bridge, org.finos.legend.pure.m3.coreinsta Class c = ((CompiledExecutionSupport) es).getClassLoader().loadClass(JavaPackageAndImportBuilder.platformJavaPackage() + "." + Pure.elementToPath(aClass, "_", true) + "_Impl"); Any result = (Any) c.getConstructor(String.class).newInstance(name); // Set default values - aClass._properties().forEach(new CheckedProcedure>() + RichIterable classProperties = _Class.getSimpleProperties(aClass, ((CompiledExecutionSupport) es).getProcessorSupport()); + classProperties.forEach(new CheckedProcedure() { @Override - public void safeValue(Property p) throws Exception + public void safeValue(CoreInstance p) throws Exception { - DefaultValue defaultValue = p._defaultValue(); - if (defaultValue != null) + if (p instanceof Property) { - Object res = reactivate(defaultValue._functionDefinition()._expressionSequence().getFirst(), new PureMap(Maps.fixedSize.empty()), bridge, es); - Method method = c.getMethod("_" + p._name(), RichIterable.class); - if (res instanceof RichIterable) + Property prop = (Property) p; + DefaultValue defaultValue = prop._defaultValue(); + if (defaultValue != null) { - method.invoke(result, res); - } - else - { - method.invoke(result, Lists.fixedSize.of(res)); + Object res = reactivate(defaultValue._functionDefinition()._expressionSequence().getFirst(), new PureMap(Maps.fixedSize.empty()), bridge, es); + Method method = c.getMethod("_" + prop._name(), RichIterable.class); + if (res instanceof RichIterable) + { + method.invoke(result, res); + } + else + { + method.invoke(result, Lists.fixedSize.of(res)); + } } } }