Skip to content

Commit

Permalink
Merge 9702ad0 into 448e7a1
Browse files Browse the repository at this point in the history
  • Loading branch information
jas-valgotar committed Aug 18, 2022
2 parents 448e7a1 + 9702ad0 commit 3ab49ac
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libraries/Microsoft.PowerFx.Core/Types/DType.cs
Expand Up @@ -2345,7 +2345,12 @@ private static DType SupertypeAggregateCore(DType type1, DType type2, bool useLe
}

Contracts.Assert(!fError);
return new DType(type1.Kind, treeRes, UnionDataSourceInfoMetadata(type1, type2));
var returnType = new DType(type1.Kind, treeRes, UnionDataSourceInfoMetadata(type1, type2), type1.DisplayNameProvider);

returnType = type2.DisplayNameProvider == null ?
returnType :
AttachOrDisableDisplayNameProvider(returnType, type2.DisplayNameProvider);
return returnType;
}

// Produces the union of the two given types.
Expand Down
35 changes: 35 additions & 0 deletions src/tests/Microsoft.PowerFx.Core.Tests/DisplayNameTests.cs
Expand Up @@ -263,5 +263,40 @@ public void ValidateExpressionConversionCommaSeparatedLocale(string inputExpress
Assert.Equal(outputExpression, outInvariantExpression);
}
}

[Theory]
[InlineData("r1.Display1", true)]
[InlineData("If(true, r1).Display1", true)]
[InlineData("If(true, r1, r1).Display1", true)]
[InlineData("If(true, Blank(), r1).Display1", true)]

// If types are different, you have no access to Display name.
[InlineData("If(true, r1, r2).Display1", false)]
[InlineData("If(true, r1, r2).Display0", false)]
[InlineData("If(true, r1, {Display1 : 123}).Display1", false)]

// If types are different, you have access to logical name, only if the name and type are same!
[InlineData("If(true, r1, r2).F1", true)]
[InlineData("If(false, r1, r2).F1", true)]
[InlineData("If(true, r1, r2).F0", false)]
public void DisplayNameTest(string input, bool succeeds)
{
var r1 = RecordType.Empty()
.Add(new NamedFormulaType("F1", FormulaType.Number, "Display1"))
.Add(new NamedFormulaType("F0", FormulaType.String, "Display0")); // F0 is Not a Common type

var r2 = RecordType.Empty()
.Add(new NamedFormulaType("F1", FormulaType.Number, "Display1"))
.Add(new NamedFormulaType("F0", FormulaType.Number, "Display0"));
var parameters = RecordType.Empty()
.Add("r1", r1)
.Add("r2", r2);

var engine = new Engine(new PowerFxConfig());

var result = engine.Check(input, parameters);
var actual = result.IsSuccess;
Assert.Equal(succeeds, actual);
}
}
}

0 comments on commit 3ab49ac

Please sign in to comment.