Power-Fx
Power-Fx copied to clipboard
Unexpected void type in the formula
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);
}
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?
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, "")
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.
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.