diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs index 4865ca8408253..97c42b9e5665e 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs @@ -703,7 +703,9 @@ private IOperation CreateBoundObjectCreationExpressionOperation(BoundObjectCreat ConstantValue? constantValue = boundObjectCreationExpression.ConstantValue; bool isImplicit = boundObjectCreationExpression.WasCompilerGenerated; - if (boundObjectCreationExpression.ResultKind == LookupResultKind.OverloadResolutionFailure || constructor == null || constructor.OriginalDefinition is ErrorMethodSymbol) + Debug.Assert(constructor is not null); + + if (boundObjectCreationExpression.ResultKind == LookupResultKind.OverloadResolutionFailure || constructor.OriginalDefinition is ErrorMethodSymbol) { var children = CreateFromArray(((IBoundInvalidNode)boundObjectCreationExpression).InvalidNodeChildren); return new InvalidOperation(children, _semanticModel, syntax, type, constantValue, isImplicit); diff --git a/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.vb b/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.vb index 2422a4b0d9712..dcc3ebe8b8b95 100644 --- a/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.vb +++ b/src/Compilers/VisualBasic/Test/IOperation/IOperation/IOperationTests_IObjectCreationExpression.vb @@ -1252,6 +1252,36 @@ IObjectCreationOperation (Constructor: Sub S..ctor()) (OperationKind.ObjectCreat VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub + + + Public Sub ObjectCreationCollectionWithInaccessibleStructureConstructor() + Dim source = .Value + + Dim expectedDiagnostics = .Value + + Dim expectedOperationTree = ) (OperationKind.ObjectCreation, Type: C.S, IsInvalid) (Syntax: 'New C.S()') + Arguments(0) + Initializer: + null +]]>.Value + + VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) + End Sub + Public Sub ObjectCreationFlow_01()