Skip to content

Commit

Permalink
Change from error to warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
jas-valgotar committed Apr 11, 2024
1 parent d228f25 commit ae837ae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,7 @@ public override void PostVisit(BinaryOpNode node)
// Helps warn no op comparison, e.g. Filter(table, ThisRecord.Value = Value)) or Filter(table, Value = Value)
if (IsNoOPFirstNameComparison(node))
{
_txb.ErrorContainer.EnsureError(DocumentErrorSeverity.Severe, node, TexlStrings.WrnNoOpFieldComparison);
_txb.ErrorContainer.EnsureError(DocumentErrorSeverity.Warning, node, TexlStrings.WrnNoOpFieldComparison);
}

var res = CheckBinaryOpCore(_txb.ErrorContainer, node, _txb.Features, leftType, rightType, _txb.BindingConfig.NumberIsFloat);
Expand Down
66 changes: 52 additions & 14 deletions src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2221,12 +2221,12 @@ public void TestTexlFunctionGetSignaturesApi()
[Fact]
public void TestWarningsOnEqualWithIncompatibleTypes()
{
TestBindingWarning("1 = \"hello\"", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("1 <> \"hello\"", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("true = 123", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("true <> 123", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("false = \"false\"", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("false <> \"false\"", DType.Boolean, expectedErrorCount: 1);
TestBindingWarning("1 = \"hello\"", expectedErrorCount: 1, expectedType: DType.Boolean);
TestBindingWarning("1 <> \"hello\"", expectedErrorCount: 1, expectedType: DType.Boolean);
TestBindingWarning("true = 123", expectedErrorCount: 1, expectedType: DType.Boolean);
TestBindingWarning("true <> 123", expectedErrorCount: 1, expectedType: DType.Boolean);
TestBindingWarning("false = \"false\"", expectedErrorCount: 1, expectedType: DType.Boolean);
TestBindingWarning("false <> \"false\"", expectedErrorCount: 1, expectedType: DType.Boolean);
}

[Fact]
Expand Down Expand Up @@ -3024,8 +3024,8 @@ public void TestWarningOnLiteralPredicate(string script, string expectedType)
symbol.AddVariable("TW", new TableType(TestUtils.DT("*[Item:w]")));
TestBindingWarning(
script,
TestUtils.DT(expectedType),
expectedErrorCount: null,
expectedType: TestUtils.DT(expectedType),
symbolTable: symbol);
}

Expand All @@ -3043,8 +3043,8 @@ public void TestWarningOnLiteralPredicate_NumberIsFloat(string script, string ex
symbol.AddVariable("TW", new TableType(TestUtils.DT("*[Item:w]")));
TestBindingWarning(
script,
TestUtils.DT(expectedType),
expectedErrorCount: null,
expectedErrorCount: null,
expectedType: TestUtils.DT(expectedType),
symbolTable: symbol,
numberIsFloat: true);
}
Expand Down Expand Up @@ -4196,12 +4196,46 @@ public void TexlFunctionTypeSemanticsTable_Delegation(string script, string expe

TestBindingWarning(
script,
TestUtils.DT(expectedSchema),
errorCount,
expectedType: TestUtils.DT(expectedSchema),
symbol,
features: Features.PowerFxV1);
}

[Theory]

[InlineData("logicalNum = logicalNum")]
[InlineData("ThisRecord.logicalNum = logicalNum")]
[InlineData("logicalNum = ThisRecord.logicalNum")]
[InlineData("ThisRecord.logicalNum = ThisRecord.logicalNum")]

[InlineData("DisplayNum = DisplayNum")]
[InlineData("ThisRecord.DisplayNum = DisplayNum")]
[InlineData("DisplayNum = ThisRecord.DisplayNum")]
[InlineData("ThisRecord.DisplayNum = ThisRecord.DisplayNum")]

[InlineData("Filter(tableVar, f1 = f1)")]
[InlineData("Filter(tableVar, ThisRecord.f1 = f1)")]
[InlineData("Filter(tableVar, f1 = ThisRecord.f1)")]
[InlineData("Filter(tableVar, ThisRecord.f1 = ThisRecord.f1)")]

[InlineData("Filter(tableVar, F1 = F1)")]
[InlineData("Filter(tableVar, ThisRecord.F1 = F1)")]
[InlineData("Filter(tableVar, F1 = ThisRecord.F1)")]
[InlineData("Filter(tableVar, ThisRecord.F1 = ThisRecord.F1)")]
public void SameFirstNameNodeComparisonWarning(string script)
{
var tableVarType = RecordType.Empty().Add("f1", FormulaType.String, "F1").ToTable();
var symbolRecord = RecordType.Empty().Add("logicalNum", FormulaType.Number, "DisplayNum").Add("tableVar", tableVarType, "TableVar");
var symbol = new SymbolTableOverRecordType(symbolRecord, allowThisRecord: true);

TestBindingWarning(
script,
expectedErrorCount: 1,
symbolTable: symbol,
features: Features.PowerFxV1);
}

private void TestBindingPurity(string script, bool isPure, SymbolTable symbolTable = null)
{
var config = new PowerFxConfig
Expand All @@ -4216,7 +4250,7 @@ private void TestBindingPurity(string script, bool isPure, SymbolTable symbolTab
Assert.Equal(isPure, result.Binding.IsPure(result.Parse.Root));
}

private void TestBindingWarning(string script, DType expectedType, int? expectedErrorCount, SymbolTable symbolTable = null, bool numberIsFloat = false, Features features = null)
private void TestBindingWarning(string script, int? expectedErrorCount, DType expectedType = null, ReadOnlySymbolTable symbolTable = null, bool numberIsFloat = false, Features features = null)
{
var config = features != null ? new PowerFxConfig(features) : new PowerFxConfig(Features.None);
var parserOptions = new ParserOptions()
Expand All @@ -4225,9 +4259,13 @@ private void TestBindingWarning(string script, DType expectedType, int? expected
};

var engine = new Engine(config);
var result = engine.Check(script, parserOptions, symbolTable);

Assert.Equal(expectedType, result.Binding.ResultType);
var result = engine.Check(script, parserOptions, symbolTable);

if (expectedType != null)
{
Assert.Equal(expectedType, result.Binding.ResultType);
}

Assert.True(result.Binding.ErrorContainer.HasErrors());
if (expectedErrorCount != null)
{
Expand Down

0 comments on commit ae837ae

Please sign in to comment.