microsoft / Power-Fx

Power Fx low-code programming language
MIT License
3.21k stars 327 forks source link

Method to determine if Formula Types can be copied #1758

Open MikeStall opened 1 year ago

MikeStall commented 1 year ago

Set(x, dataverseRecord) will fail since dataverseRecord is not a copyable type. (enforced with #1633) But really, we should be blocking this at time of creating variable 'x' if it's a non-copyable type.

Here's the check we do in Set() to block this https://github.com/microsoft/Power-Fx/blob/ee877354b4c0392d7e0d8244e6348fa5ce399d61/src/libraries/Microsoft.PowerFx.Interpreter/Functions/SetFunction.cs#L92C30-L92C54

This should be using a public property on FormulaType that hosts can check as well.

More broadly, there may be other open issues here:

  1. do we need the check in Set()? Or should it just be blocked at creating the variable.
  2. be sure to check for nested types. Set(x, {nested: dataverseRecord}) should fail too.
MikeStall commented 1 year ago

A basic workaround is: bool IsDVType(FormulaType t) => (t as AggregateType)?.TableSymbolName != null;