finos / legend-pure

Legend Pure module
https://legend.finos.org
Apache License 2.0
66 stars 136 forks source link

Avoid direct casting primitive core instances #678

Closed rafaelbey closed 1 year ago

rafaelbey commented 1 year ago

This PR proposes a change to avoid direct casting primitive core instances during interpreted flow to better interoperate with compile primitives ValCoreInstance. By delegating to the primitive class, we can either direct cast or create a new instance to meet the expected type.

This is important for the legend-engine compile function, as interpreted flow interoperate with compiled instances. Without this change, the code ends on class cast exception like this:

Caused by: java.lang.ClassCastException: class org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ValCoreInstance cannot be cast to class org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance (org.finos.legend.pure.runtime.java.compiled.generation.processors.support.coreinstance.ValCoreInstance and org.finos.legend.pure.m4.coreinstance.primitive.StringCoreInstance are in unnamed module of loader 'app')
    at org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinitionInstance.addKeyValue(ConcreteFunctionDefinitionInstance.java:1012)
    at org.finos.legend.pure.m3.navigation.Instance.addValueToProperty(Instance.java:90)
    at org.finos.legend.pure.runtime.java.interpreted.natives.grammar.lang.Copy.copy(Copy.java:204)
    at org.finos.legend.pure.runtime.java.interpreted.natives.grammar.lang.Copy.execute(Copy.java:165)
    at org.finos.legend.pure.runtime.java.interpreted.FunctionExecutionInterpreted.executeFunction(FunctionExecutionInterpreted.java:486)
    ... 34 more
github-actions[bot] commented 1 year ago

Test Results

   513 files  ±0     513 suites  ±0   29m 13s :stopwatch: - 2m 36s 3 791 tests ±0  3 759 :heavy_check_mark: ±0  32 :zzz: ±0  0 :x: ±0  5 088 runs  ±0  5 056 :heavy_check_mark: ±0  32 :zzz: ±0  0 :x: ±0 

Results for commit 9c9d8524. ± Comparison against base commit 1e3f0924.

:recycle: This comment has been updated with latest results.