diff --git a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs index a78368ebaa..6850c202ef 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs @@ -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); diff --git a/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs b/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs index 92e9e3fe70..babde6b0df 100644 --- a/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs +++ b/src/tests/Microsoft.PowerFx.Core.Tests/TexlTests.cs @@ -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] @@ -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); } @@ -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); } @@ -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 @@ -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() @@ -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) {