diff --git a/src/Features/CSharpTest/GenerateVariable/GenerateVariableTests.cs b/src/Features/CSharpTest/GenerateVariable/GenerateVariableTests.cs index 9d5b656ce90e5..ebdd52c0bb2f0 100644 --- a/src/Features/CSharpTest/GenerateVariable/GenerateVariableTests.cs +++ b/src/Features/CSharpTest/GenerateVariable/GenerateVariableTests.cs @@ -11065,15 +11065,77 @@ public async Task M(out int x, int y, System.TimeSpan time, out int z, params do public async Task TestMissingWhenGeneratingFunctionPointer() { await TestMissingInRegularAndScriptAsync( -@"using System; + """ + using System; -public unsafe class Bar -{ - public static ZZZ() - { - delegate* i = &[|Goo|]; - } -}"); + public unsafe class Bar + { + public static ZZZ() + { + delegate* i = &[|Goo|]; + } + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68322")] + public async Task TestImplicitObjectCreationExpression() + { + await TestInRegularAndScriptAsync( + """ + class Example + { + public Example(int argument) { } + + void M() + { + Example e = new([|_field|]); + } + } + """, + """ + class Example + { + private int _field; + + public Example(int argument) { } + + void M() + { + Example e = new(_field); + } + } + """); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68322")] + public async Task TestImplicitCollectionCreationExpression() + { + await TestInRegularAndScriptAsync( + """ + using System.Collections.Generic; + + class Example + { + void M() + { + List list = new() { [|_field|] }; + } + } + """, + """ + using System.Collections.Generic; + + class Example + { + private int _field; + + void M() + { + List list = new() { [|_field|] }; + } + } + """); } } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index 889e39bee75b5..a9d97b5c31664 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -292,7 +292,7 @@ private IEnumerable InferTypeInArgument( return InferTypeInInvocationExpression(invocation, index, argument); } - if (argument.Parent?.Parent is ObjectCreationExpressionSyntax creation) + if (argument.Parent?.Parent is BaseObjectCreationExpressionSyntax creation) { // new Outer(Goo()); // @@ -323,7 +323,7 @@ private IEnumerable InferTypeInArgument( if (argument.Parent.IsParentKind(SyntaxKind.ImplicitElementAccess) && argument.Parent.Parent.IsParentKind(SyntaxKind.SimpleAssignmentExpression) && argument.Parent.Parent.Parent.IsParentKind(SyntaxKind.ObjectInitializerExpression) && - argument.Parent.Parent.Parent.Parent?.Parent is ObjectCreationExpressionSyntax objectCreation) + argument.Parent.Parent.Parent.Parent?.Parent is BaseObjectCreationExpressionSyntax objectCreation) { var types = GetTypes(objectCreation).Select(t => t.InferredType);