diff --git a/Src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs b/Src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs index 8fe31748897b2dab186f3d150c62566b3e98e365..c74315514f4631697d827c4b34120a421dec3b1d 100644 --- a/Src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs +++ b/Src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs @@ -821,7 +821,9 @@ private BoundExpression VisitObjectCreationExpressionInternal(BoundObjectCreatio return Constant(node); } - if ((object)node.Constructor == null || node.Arguments.Length == 0) + if ((object)node.Constructor == null || + (node.Arguments.Length == 0 && !node.Type.IsStructType()) || + node.Constructor.IsDefaultValueTypeConstructor()) { return ExprFactory("New", Bound.Typeof(node.Type)); } diff --git a/Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConstructorInitTests.cs b/Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConstructorInitTests.cs index c68195dd65fc9ffd0be7f5ff2f5f94aa00f73ef1..473aced1095643f2322b10e6f57c377cba36e7e1 100644 --- a/Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConstructorInitTests.cs +++ b/Src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenConstructorInitTests.cs @@ -810,5 +810,30 @@ static void Main() CompileAndVerifyExperimental(source, expectedOutput: "0"); } + + [Fact] + public void InstanceInitializerStructInExprTree() + { + var source = @" + +using System; +using System.Linq.Expressions; + +class C +{ + struct S1 + { + public int x = 42; + } + + static void Main() + { + Expression> testExpr = () => new S1(); + System.Console.Write(testExpr.Compile()().x); + } +} +"; + CompileAndVerifyExperimental(source, additionalRefs: new[] { ExpressionAssemblyRef }, expectedOutput: "42"); + } } }