Skip to content

C# 11: Check that we get AST for structs that doesn't initialise all fields. #12058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions csharp/ql/test/library-tests/csharp11/PrintAst.expected
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,33 @@ Struct.cs:
# 12| -1: [TypeMention] object
# 13| 11: [Field] MyReadonlyString
# 13| -1: [TypeMention] string
StructDefault.cs:
# 1| [Class] MyEmptyClass
# 2| [Struct] StructDefaultValue
# 4| 5: [Field] X
# 4| -1: [TypeMention] int
# 5| 6: [Field] Y
# 5| -1: [TypeMention] int
# 6| 7: [Field] Z
# 6| -1: [TypeMention] MyEmptyClass
# 8| 8: [InstanceConstructor] StructDefaultValue
#-----| 2: (Parameters)
# 8| 0: [Parameter] x
# 8| -1: [TypeMention] int
# 8| 1: [Parameter] inity
# 8| -1: [TypeMention] bool
# 9| 4: [BlockStmt] {...}
# 10| 0: [ExprStmt] ...;
# 10| 0: [AssignExpr] ... = ...
# 10| 0: [FieldAccess] access to field X
# 10| 1: [ParameterAccess] access to parameter x
# 11| 1: [IfStmt] if (...) ...
# 11| 0: [ParameterAccess] access to parameter inity
# 11| 1: [BlockStmt] {...}
# 11| 0: [ExprStmt] ...;
# 11| 0: [AssignExpr] ... = ...
# 11| 0: [FieldAccess] access to field Y
# 11| 1: [IntLiteral] 1
cil/class1.cs:
# 4| [Class] Class1
# 6| 5: [Method] Main
Expand Down
13 changes: 13 additions & 0 deletions csharp/ql/test/library-tests/csharp11/StructDefault.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class MyEmptyClass { }
public struct StructDefaultValue
{
public int X;
public int Y;
public MyEmptyClass? Z;

public StructDefaultValue(int x, bool inity)
{
X = x;
if (inity) { Y = 1; }
}
}