From 15eebe97a6809c316014c199e1cb88f76c42d49d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 07:03:31 +0000 Subject: [PATCH 1/4] Initial plan From ed2ebb4c83e4a139bdaaa4b32872093a838e6952 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 07:17:49 +0000 Subject: [PATCH 2/4] Fix error when parsing nested object initialization (issue #701) Agent-Logs-Url: https://github.com/zzzprojects/System.Linq.Dynamic.Core/sessions/4683789c-0227-43d7-9432-4863adea1d4c Co-authored-by: StefH <249938+StefH@users.noreply.github.com> --- .../Parser/ExpressionParser.cs | 59 ++++++++++++++++++- .../DynamicExpressionParserTests.cs | 29 +++++++++ 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index dcf6a329..908ef3b5 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -1678,14 +1678,67 @@ private Expression CreateNewExpression(List properties, List(new ParsingConfig(), false, "new[]{1,2,3}.Any(z => z > 0)"); } + // https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/701 + [Fact] + public void DynamicExpressionParser_ParseLambda_NestedObjectInitialization() + { + // Arrange + var srcType = typeof(CustomerForNestedNewTest); + + // Act + var lambda = DynamicExpressionParser.ParseLambda(ParsingConfig.DefaultEFCore21, srcType, srcType, "new (new (3 as Id) as CurrentDepartment)"); + var @delegate = lambda.Compile(); + var result = (CustomerForNestedNewTest)@delegate.DynamicInvoke(new CustomerForNestedNewTest())!; + + // Assert + result.Should().NotBeNull(); + result.CurrentDepartment.Should().NotBeNull(); + result.CurrentDepartment!.Id.Should().Be(3); + } + + public class CustomerForNestedNewTest + { + public int Id { get; set; } + public DepartmentForNestedNewTest? CurrentDepartment { get; set; } + } + + public class DepartmentForNestedNewTest + { + public int Id { get; set; } + } + public class DefaultDynamicLinqCustomTypeProviderForGenericExtensionMethod : DefaultDynamicLinqCustomTypeProvider { public DefaultDynamicLinqCustomTypeProviderForGenericExtensionMethod() : base(ParsingConfig.Default) From 417258d5c5b1fb8cf4e01989043786153866a3df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 14:34:10 +0000 Subject: [PATCH 3/4] Refactor TryRebuildMemberInitExpression to use out parameter pattern Agent-Logs-Url: https://github.com/zzzprojects/System.Linq.Dynamic.Core/sessions/537f61ea-9dbe-4ae4-9fa8-0358f826f195 Co-authored-by: StefH <249938+StefH@users.noreply.github.com> --- .../Parser/ExpressionParser.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs index 908ef3b5..4a6319aa 100644 --- a/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/Parser/ExpressionParser.cs @@ -1681,9 +1681,10 @@ private Expression CreateNewExpression(List properties, List properties, List properties, List properties, List properties, List Date: Sun, 29 Mar 2026 16:46:15 +0000 Subject: [PATCH 4/4] Add three-level-deep nested new test to exercise recursive TryRebuildMemberInitExpression Agent-Logs-Url: https://github.com/zzzprojects/System.Linq.Dynamic.Core/sessions/42b1ec4e-90f4-484b-ae3a-73f3bee9c50b Co-authored-by: StefH <249938+StefH@users.noreply.github.com> --- .../DynamicExpressionParserTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs index acf65082..4417d1a0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs @@ -2321,13 +2321,46 @@ public void DynamicExpressionParser_ParseLambda_NestedObjectInitialization() result.CurrentDepartment!.Id.Should().Be(3); } + // https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/701 + [Fact] + public void DynamicExpressionParser_ParseLambda_NestedObjectInitialization_ThreeLevelsDeep() + { + // Arrange — exercises the recursive TryRebuildMemberInitExpression path. + // The parser propagates _resultType (CustomerForNestedNewTest) into all nested new + // expressions. The middle "new (new (3 as Id) as Sub)" therefore builds a + // MIE{ Sub = MIE{Id=3} }. When the outer new binds that to its own + // "Sub" property (type DepartmentForNestedNewTest), TryRebuildMemberInitExpression is + // called and encounters the inner MIE{Id=3} binding — a MemberInitExpression + // itself — which triggers the recursive call to rebuild it for SubDepartmentForNestedNewTest. + var srcType = typeof(CustomerForNestedNewTest); + + // Act + var lambda = DynamicExpressionParser.ParseLambda(ParsingConfig.DefaultEFCore21, srcType, srcType, + "new (new (new (3 as Id) as Sub) as Sub)"); + var @delegate = lambda.Compile(); + var result = (CustomerForNestedNewTest)@delegate.DynamicInvoke(new CustomerForNestedNewTest())!; + + // Assert + result.Should().NotBeNull(); + result.Sub.Should().NotBeNull(); + result.Sub!.Sub.Should().NotBeNull(); + result.Sub.Sub!.Id.Should().Be(3); + } + public class CustomerForNestedNewTest { public int Id { get; set; } public DepartmentForNestedNewTest? CurrentDepartment { get; set; } + public DepartmentForNestedNewTest? Sub { get; set; } } public class DepartmentForNestedNewTest + { + public int Id { get; set; } + public SubDepartmentForNestedNewTest? Sub { get; set; } + } + + public class SubDepartmentForNestedNewTest { public int Id { get; set; } }