Skip to content

Commit

Permalink
Add IOperation test where IObjectCreationOperation.Constructor is null (
Browse files Browse the repository at this point in the history
#63092)

* Add IOperation test where IObjectCreationOperation.Constructor is null
  • Loading branch information
Youssef1313 authored Oct 21, 2022
1 parent b674ba1 commit 338932f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoundNode, IOperation>(((IBoundInvalidNode)boundObjectCreationExpression).InvalidNodeChildren);
return new InvalidOperation(children, _semanticModel, syntax, type, constantValue, isImplicit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,36 @@ IObjectCreationOperation (Constructor: Sub S..ctor()) (OperationKind.ObjectCreat
VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub

<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub ObjectCreationCollectionWithInaccessibleStructureConstructor()
Dim source = <![CDATA[
Class C
Protected Structure S
End Structure
End Class
Class D
Shared Sub M(o)
M(New C.S())'BIND:"New C.S()"
End Sub
End Class]]>.Value

Dim expectedDiagnostics = <![CDATA[
BC30389: 'C.S' is not accessible in this context because it is 'Protected'.
M(New C.S())'BIND:"New C.S()"
~~~
]]>.Value

Dim expectedOperationTree = <![CDATA[
IObjectCreationOperation (Constructor: <null>) (OperationKind.ObjectCreation, Type: C.S, IsInvalid) (Syntax: 'New C.S()')
Arguments(0)
Initializer:
null
]]>.Value

VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub

<CompilerTrait(CompilerFeature.IOperation, CompilerFeature.Dataflow)>
<Fact()>
Public Sub ObjectCreationFlow_01()
Expand Down

0 comments on commit 338932f

Please sign in to comment.