зеркало из https://github.com/microsoft/Power-Fx.git
Update the Trace function to return a Void type (#2650)
The Trace function doesn't return anything. For legacy reasons, it currently returns DType.Boolean (when it was created, we didn't have DType.Void). This PR updates it to return Void instead.
This commit is contained in:
Родитель
c0e1ad7c42
Коммит
93daa65514
|
@ -44,6 +44,13 @@ namespace Microsoft.PowerFx.Core.Texl.Builtins
|
|||
yield return new[] { TexlStrings.TraceArg1, TexlStrings.TraceArg2, TexlStrings.TraceArg3, TexlStrings.TraceArg4 };
|
||||
}
|
||||
|
||||
public override bool CheckTypes(CheckTypesContext context, TexlNode[] args, DType[] argTypes, IErrorContainer errors, out DType returnType, out Dictionary<TexlNode, DType> nodeToCoercedTypeMap)
|
||||
{
|
||||
var result = base.CheckTypes(context, args, argTypes, errors, out returnType, out nodeToCoercedTypeMap);
|
||||
returnType = context.Features.PowerFxV1CompatibilityRules ? DType.Void : DType.Boolean;
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void CheckSemantics(TexlBinding binding, TexlNode[] args, DType[] argTypes, IErrorContainer errors)
|
||||
{
|
||||
Contracts.AssertValue(args);
|
||||
|
|
|
@ -2797,7 +2797,7 @@ namespace Microsoft.PowerFx.Functions
|
|||
throw new CustomFunctionErrorException(ex.Message);
|
||||
}
|
||||
|
||||
return FormulaValue.New(true);
|
||||
return irContext.ResultType._type.Kind == DKind.Boolean ? FormulaValue.New(true) : FormulaValue.NewVoid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2693,6 +2693,25 @@ namespace Microsoft.PowerFx.Core.Tests
|
|||
features: Features.PowerFxV1);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Trace(\"hello\")")]
|
||||
[InlineData("Trace(\"hello\", TraceSeverity.Warning)")]
|
||||
[InlineData("Trace(\"hello\", TraceSeverity.Warning, { a: 1 })")]
|
||||
public void TexlFunctionTypeSemanticsTrace(string expression)
|
||||
{
|
||||
foreach (var powerFxV1 in new[] { false, true })
|
||||
{
|
||||
var features = powerFxV1 ? Features.PowerFxV1 : Features.None;
|
||||
var engine = new Engine(new PowerFxConfig(features));
|
||||
var options = new ParserOptions() { AllowsSideEffects = true };
|
||||
var result = engine.Check(expression, options);
|
||||
|
||||
var expectedType = powerFxV1 ? DType.Void : DType.Boolean;
|
||||
Assert.Equal(expectedType, result.Binding.ResultType);
|
||||
Assert.True(result.IsSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Concat([], \"\")")]
|
||||
[InlineData("Concat([1, 2, 3], Text(Value))")]
|
||||
|
|
Загрузка…
Ссылка в новой задаче