Power-Fx icon indicating copy to clipboard operation
Power-Fx copied to clipboard

Void issues

Open jas-valgotar opened this issue 7 months ago • 1 comments

  1. IsError( If( false, GUID(), Now() ) ) returns false

  2. If(false, {}, []) -> returns empty table, should be error

  3. If(False, {}, 1) -> returns 1 should be an error.

2&3 seems to be due to special casing here. https://github.com/microsoft/Power-Fx/blob/81e7c0bee1e1b3dc45f03ed302d2592cf316bd54/src/libraries/Microsoft.PowerFx.Core/Types/DType.cs#L3991 (Related PR: https://github.com/microsoft/Power-Fx/pull/1309)

jas-valgotar avatar Jun 18 '25 18:06 jas-valgotar

A clarification. I believe IfError(Void, 1, 2) and IsError(Void) should produce a Void compile time error only when side effects are disabled.

The reason we turn a blind eye to Void results in Canvas app Button.OnSelect is so that makers can write control flow with the If function. For example, in this case where Orders {Value: Number} and BadSessions {Value: GUID} have incompatible schemas:

​If( allGood, 
    Collect( Orders, {Value:Int(TextInput1.Text)} ), 
    Collect( BadSessions, {Value:SessionGUID} ) 
)

Makers should be able to wrap that whole formula with IfError or IsError to detect runtime problems and take appropriate actions. For example, the value of TextInput1.Text in this example may not be a parseable number.

But without side effects, the If function isn't about control flow, the formula is expected to produce a single, non Void return value. That is the breaking change that we all think is appropriate from the discussion above.

If we all agree, then the first item in Jas' list above does not require a change, after https://github.com/microsoft/Power-Fx/pull/2917 has been merged.

gregli-msft avatar Jun 21 '25 00:06 gregli-msft