Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,13 @@ private bool IsExpandedType(TexlBinding binding, TexlNode node)
{
var type = _binding?.GetTypeAllowInvalid(node);

return type != null && type.AggregateHasExpandedType();
if (type == null)
{
return false;
}

// Skip lazy aggregates: AggregateHasExpandedType forces per-field materialization.
return !type.IsLazyType && type.AggregateHasExpandedType();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,33 @@ public void ApplyLoggingWithBinding(string expr)
var anon = check.ApplyGetLogging();
}

[Fact]
public void ApplyGetLoggingDoesNotEnumerateLazyFields()
{
var spy = new LazyLoggingSpyRecordType();
var symbolTable = new SymbolTable();
symbolTable.AddVariable("MyLazy", spy);

CheckResult check = new CheckResult(new Engine())
.SetText("With({x:MyLazy}, 1)")
.SetBindingInfo(symbolTable);

check.ApplyBinding();
Assert.True(check.IsSuccess);

// Reset counters so we observe only the logging path.
spy.TryGetFieldTypeCallCount = 0;
spy.FieldNamesIterationCount = 0;

var log = check.ApplyGetLogging();

Assert.NotNull(log);
Assert.DoesNotContain("MyLazy", log);
Assert.DoesNotContain("A", log);
Assert.Equal(0, spy.TryGetFieldTypeCallCount);
Assert.Equal(0, spy.FieldNamesIterationCount);
}

[Fact]
public void TestSummary()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Collections.Generic;
using Microsoft.PowerFx.Types;

namespace Microsoft.PowerFx.Core.Tests
{
// Test helper. Lets tests assert that the logging path does not enumerate
// lazy record fields or force per-field type resolution.
public sealed class LazyLoggingSpyRecordType : RecordType
{
public int TryGetFieldTypeCallCount;
public int FieldNamesIterationCount;

public override IEnumerable<string> FieldNames => EnumerateFieldNames();

public override bool TryGetFieldType(string name, out FormulaType type)
{
TryGetFieldTypeCallCount++;
switch (name)
{
case "A":
type = FormulaType.String;
return true;
case "B":
type = FormulaType.Number;
return true;
default:
type = FormulaType.Blank;
return false;
}
}

public override bool Equals(object other)
{
return other is LazyLoggingSpyRecordType;
}

public override int GetHashCode()
{
return 0x511F;
}

private IEnumerable<string> EnumerateFieldNames()
{
FieldNamesIterationCount++;
yield return "A";
yield return "B";
}
}
}
Loading