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

Unexpected void type in the formula

Open Robulane opened this issue 1 year ago • 5 comments

This test fails

    [Fact]
    public void CheckParseSuccess()
    {
        var config = new PowerFxConfig();
        var engine = new Engine(config);
        var parse = engine.Parse("If(Len(x) = 0, y, x)");

        var r = RecordType.Empty()
            .Add(new NamedFormulaType("x", FormulaType.String))
            .Add(new NamedFormulaType("y", FormulaType.UntypedObject));

        var check = engine.Check(parse, r);
        Assert.True(check.IsSuccess);

        Assert.IsType<UntypedObjectType>(check.ReturnType);
    }

Robulane avatar Feb 21 '24 10:02 Robulane

After https://github.com/microsoft/Power-Fx/pull/2096, this result is expected. In this case, the If function has 2 incompatible possible return types. Are you experiencing any regression?

anderson-joyle avatar Feb 21 '24 16:02 anderson-joyle

I disagree that this is expected. The Void should never be returned for the expression that expects the value. You should either return the error or the type of the first argument. If the first argument is Untyped, I think you can return Untyped (because it's untyped). Expressions like this should return an error though: If(true, 2, "")

Robulane avatar Feb 21 '24 17:02 Robulane

Void will result in an error as soon as one tries to use it. There are lots of cases, especially imperative logic, where the return value is not needed and an error would be not useful.

gregli-msft avatar Feb 21 '24 17:02 gregli-msft

We should not wait the Runtime to throw an error, the check function should return the error. This makes the software that is using PowerFX less reliable for customers as errors are not caught at design time.

Robulane avatar Feb 21 '24 17:02 Robulane