Skip to content

Commit 19fac60

Browse files
authored
Merge pull request github#4661 from tamasvajk/feature/fix-var-decl-type-mention
C#: Fix parent of 'TypeMention' for some variable declaration
2 parents f43d911 + 8cbe8bc commit 19fac60

File tree

8 files changed

+31
-31
lines changed

8 files changed

+31
-31
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/VariableDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static VariableDeclaration Create(Context cx, ISymbol symbol, AnnotatedTy
1919
var l = LocalVariable.Create(cx, symbol);
2020
l.PopulateManual(ret, isVar);
2121
if (optionalSyntax != null)
22-
TypeMention.Create(cx, optionalSyntax, parent, type);
22+
TypeMention.Create(cx, optionalSyntax, ret, type);
2323
});
2424
return ret;
2525
}

csharp/ql/test/experimental/ir/ir/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ foreach.cs:
465465
# 5| 5: [IntLiteral] 6
466466
# 5| 6: [IntLiteral] 7
467467
# 7| 1: [ForeachStmt] foreach (... ... in ...) ...
468-
# 7| -1: [TypeMention] int
469468
# 7| 0: [LocalVariableDeclExpr] Int32 items
469+
# 7| 0: [TypeMention] int
470470
# 7| 1: [LocalVariableAccess] access to local variable a_array
471471
# 8| 2: [BlockStmt] {...}
472472
# 9| 0: [LocalVariableDeclStmt] ... ...;
@@ -725,9 +725,9 @@ isexpr.cs:
725725
# 12| 1: [LocalVariableAccess] access to local variable obj
726726
# 13| 2: [IfStmt] if (...) ...
727727
# 13| 0: [IsExpr] ... is ...
728-
# 13| -1: [TypeMention] Is_A
729728
# 13| 0: [LocalVariableAccess] access to local variable o
730729
# 13| 1: [VariablePatternExpr] Is_A tmp
730+
# 13| 0: [TypeMention] Is_A
731731
# 14| 1: [BlockStmt] {...}
732732
# 15| 0: [LocalVariableDeclStmt] ... ...;
733733
# 15| 0: [LocalVariableDeclAndInitExpr] Int32 res = ...

csharp/ql/test/library-tests/csharp7/PrintAst.expected

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ CSharp7.cs:
722722
# 235| 1: [IfStmt] if (...) ...
723723
# 235| 0: [LogicalAndExpr] ... && ...
724724
# 235| 0: [IsExpr] ... is ...
725-
# 235| -1: [TypeMention] int
726725
# 235| 0: [LocalVariableAccess] access to local variable o
727726
# 235| 1: [VariablePatternExpr] Int32 i1
727+
# 235| 0: [TypeMention] int
728728
# 235| 1: [GTExpr] ... > ...
729729
# 235| 0: [LocalVariableAccess] access to local variable i1
730730
# 235| 1: [IntLiteral] 0
@@ -738,9 +738,9 @@ CSharp7.cs:
738738
# 237| 1: [LocalVariableAccess] access to local variable i1
739739
# 239| 2: [IfStmt] if (...) ...
740740
# 239| 0: [IsExpr] ... is ...
741-
# 239| -1: [TypeMention] string
742741
# 239| 0: [LocalVariableAccess] access to local variable o
743742
# 239| 1: [VariablePatternExpr] String s1
743+
# 239| 0: [TypeMention] string
744744
# 240| 1: [BlockStmt] {...}
745745
# 241| 0: [ExprStmt] ...;
746746
# 241| 0: [MethodCall] call to method WriteLine
@@ -774,9 +774,9 @@ CSharp7.cs:
774774
# 256| 4: [ConstCase] case ...:
775775
# 256| 0: [ConstantPatternExpr,StringLiteral] "x"
776776
# 256| 1: [IsExpr] ... is ...
777-
# 256| -1: [TypeMention] string
778777
# 256| 0: [LocalVariableAccess] access to local variable o
779778
# 256| 1: [VariablePatternExpr] String s4
779+
# 256| 0: [TypeMention] string
780780
# 257| 5: [ExprStmt] ...;
781781
# 257| 0: [MethodCall] call to method WriteLine
782782
# 257| -1: [TypeAccess] access to type Console
@@ -786,8 +786,8 @@ CSharp7.cs:
786786
# 257| 1: [LocalVariableAccess] access to local variable s4
787787
# 258| 6: [BreakStmt] break;
788788
# 259| 7: [CaseStmt] case ...:
789-
# 259| -1: [TypeMention] int
790789
# 259| 0: [VariablePatternExpr] Int32 i2
790+
# 259| 0: [TypeMention] int
791791
# 259| 1: [GTExpr] ... > ...
792792
# 259| 0: [LocalVariableAccess] access to local variable i2
793793
# 259| 1: [IntLiteral] 0
@@ -800,8 +800,8 @@ CSharp7.cs:
800800
# 260| 1: [LocalVariableAccess] access to local variable i2
801801
# 261| 9: [BreakStmt] break;
802802
# 262| 10: [CaseStmt] case ...:
803-
# 262| -1: [TypeMention] int
804803
# 262| 0: [VariablePatternExpr] Int32 i3
804+
# 262| 0: [TypeMention] int
805805
# 263| 11: [ExprStmt] ...;
806806
# 263| 0: [MethodCall] call to method WriteLine
807807
# 263| -1: [TypeAccess] access to type Console
@@ -811,8 +811,8 @@ CSharp7.cs:
811811
# 263| 1: [LocalVariableAccess] access to local variable i3
812812
# 264| 12: [BreakStmt] break;
813813
# 265| 13: [CaseStmt] case ...:
814-
# 265| -1: [TypeMention] string
815814
# 265| 0: [VariablePatternExpr] String s2
815+
# 265| 0: [TypeMention] string
816816
# 266| 14: [ExprStmt] ...;
817817
# 266| 0: [MethodCall] call to method WriteLine
818818
# 266| -1: [TypeAccess] access to type Console
@@ -898,9 +898,9 @@ CSharp7.cs:
898898
# 299| 0: [LocalVariableAccess] access to local variable x
899899
# 299| 1: [IntLiteral] 10
900900
# 299| 1: [IsExpr] ... is ...
901-
# 299| -1: [TypeMention] int
902901
# 299| 0: [LocalVariableAccess] access to local variable x
903902
# 299| 1: [VariablePatternExpr] Int32 y
903+
# 299| 0: [TypeMention] int
904904
# 299| 1: [PreIncrExpr] ++...
905905
# 299| 0: [LocalVariableAccess] access to local variable x
906906
# 300| 2: [BlockStmt] {...}

csharp/ql/test/library-tests/csharp8/PrintAst.expected

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ AsyncStreams.cs:
3636
# 17| -1: [TypeMention] Void
3737
# 18| 4: [BlockStmt] {...}
3838
# 19| 0: [ForeachStmt] foreach (... ... in ...) ...
39-
# 19| -1: [TypeMention] int
4039
# 19| 0: [LocalVariableDeclExpr] Int32 item
40+
# 19| 0: [TypeMention] int
4141
# 19| 1: [MethodCall] call to method Items
4242
# 20| 2: [ExprStmt] ...;
4343
# 20| 0: [MethodCall] call to method WriteLine
@@ -744,9 +744,9 @@ patterns.cs:
744744
# 7| 1: [IntLiteral] 2
745745
# 9| 1: [IfStmt] if (...) ...
746746
# 9| 0: [IsExpr] ... is ...
747-
# 9| -1: [TypeMention] MyStruct
748747
# 9| 0: [LocalVariableAccess] access to local variable o
749748
# 9| 1: [VariablePatternExpr] MyStruct ms1
749+
# 9| 0: [TypeMention] MyStruct
750750
# 10| 1: [BlockStmt] {...}
751751
# 13| 2: [IfStmt] if (...) ...
752752
# 13| 0: [LogicalAndExpr] ... && ...
@@ -758,8 +758,8 @@ patterns.cs:
758758
# 13| 1: [TypeAccess] access to type MyStruct
759759
# 13| 0: [TypeMention] MyStruct
760760
# 13| 3: [PropertyPatternExpr] { ... }
761-
# 13| -1: [TypeMention] int
762761
# 13| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x
762+
# 13| 0: [TypeMention] int
763763
# 13| 1: [LTExpr] ... < ...
764764
# 13| 0: [LocalVariableAccess] access to local variable x
765765
# 13| 1: [IntLiteral] 4
@@ -818,8 +818,8 @@ patterns.cs:
818818
# 36| 1: [SwitchStmt] switch (...) {...}
819819
# 36| 0: [LocalVariableAccess] access to local variable s
820820
# 38| 0: [CaseStmt] case ...:
821-
# 38| -1: [TypeMention] MyStruct
822821
# 38| 0: [VariablePatternExpr] MyStruct ms1
822+
# 38| 0: [TypeMention] MyStruct
823823
# 38| 1: [EQExpr] ... == ...
824824
# 38| 0: [FieldAccess] access to field X
825825
# 38| -1: [LocalVariableAccess] access to local variable ms1
@@ -831,8 +831,8 @@ patterns.cs:
831831
# 39| 0: [StringLiteral] "Hit the breakpoint"
832832
# 40| 2: [BreakStmt] break;
833833
# 41| 3: [CaseStmt] case ...:
834-
# 41| -1: [TypeMention] MyStruct
835834
# 41| 0: [VariablePatternExpr] MyStruct ms2
835+
# 41| 0: [TypeMention] MyStruct
836836
# 41| 1: [LTExpr] ... < ...
837837
# 41| 0: [FieldAccess] access to field X
838838
# 41| -1: [LocalVariableAccess] access to local variable ms2
@@ -850,8 +850,8 @@ patterns.cs:
850850
# 48| 1: [TypeAccess] access to type MyStruct
851851
# 48| 0: [TypeMention] MyStruct
852852
# 48| 3: [PropertyPatternExpr] { ... }
853-
# 48| -1: [TypeMention] int
854853
# 48| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x
854+
# 48| 0: [TypeMention] int
855855
# 48| 1: [GTExpr] ... > ...
856856
# 48| 0: [LocalVariableAccess] access to local variable x
857857
# 48| 1: [IntLiteral] 2
@@ -877,8 +877,8 @@ patterns.cs:
877877
# 54| 6: [CaseStmt] case ...:
878878
# 54| 0: [RecursivePatternExpr] { ... }
879879
# 54| 3: [PropertyPatternExpr] { ... }
880-
# 54| -1: [TypeMention] int
881880
# 54| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x2
881+
# 54| 0: [TypeMention] int
882882
# 54| 1: [GTExpr] ... > ...
883883
# 54| 0: [LocalVariableAccess] access to local variable x2
884884
# 54| 1: [IntLiteral] 2
@@ -908,8 +908,8 @@ patterns.cs:
908908
# 67| 1: [TypeAccess] access to type MyStruct
909909
# 67| 0: [TypeMention] MyStruct
910910
# 67| 3: [PropertyPatternExpr] { ... }
911-
# 67| -1: [TypeMention] int
912911
# 67| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x
912+
# 67| 0: [TypeMention] int
913913
# 67| 1: [GTExpr] ... > ...
914914
# 67| 0: [LocalVariableAccess] access to local variable x
915915
# 67| 1: [IntLiteral] 2
@@ -942,10 +942,10 @@ patterns.cs:
942942
# 78| 0: [CaseStmt] case ...:
943943
# 78| 0: [RecursivePatternExpr] { ... }
944944
# 78| 2: [PositionalPatternExpr] ( ... )
945-
# 78| -1: [TypeMention] int
946-
# 78| -1: [TypeMention] float
947945
# 78| 0: [VariablePatternExpr] Int32 x
946+
# 78| 0: [TypeMention] int
948947
# 78| 1: [VariablePatternExpr] Single y
948+
# 78| 0: [TypeMention] float
949949
# 78| 1: [LTExpr] ... < ...
950950
# 78| 0: [CastExpr] (...) ...
951951
# 78| 1: [LocalVariableAccess] access to local variable x
@@ -998,8 +998,8 @@ patterns.cs:
998998
# 100| 1: [SwitchExpr] ... switch { ... }
999999
# 100| -1: [ParameterAccess] access to parameter x
10001000
# 101| 0: [SwitchCaseExpr] ... => ...
1001-
# 101| -1: [TypeMention] int
10021001
# 101| 0: [VariablePatternExpr] Int32 y
1002+
# 101| 0: [TypeMention] int
10031003
# 101| 1: [GTExpr] ... > ...
10041004
# 101| 0: [LocalVariableAccess] access to local variable y
10051005
# 101| 1: [IntLiteral] 10
@@ -1101,8 +1101,8 @@ patterns.cs:
11011101
# 128| 1: [TypeAccess] access to type MyStruct
11021102
# 128| 0: [TypeMention] MyStruct
11031103
# 128| 3: [PropertyPatternExpr] { ... }
1104-
# 128| -1: [TypeMention] int
11051104
# 128| 0: [LabeledPatternExpr,VariablePatternExpr] Int32 x
1105+
# 128| 0: [TypeMention] int
11061106
# 128| 1: [GTExpr] ... > ...
11071107
# 128| 0: [LocalVariableAccess] access to local variable x
11081108
# 128| 1: [IntLiteral] 2
@@ -1142,8 +1142,8 @@ patterns.cs:
11421142
# 139| 0: [ConstantPatternExpr,IntLiteral] 2
11431143
# 139| 2: [IntLiteral] 3
11441144
# 140| 2: [SwitchCaseExpr] ... => ...
1145-
# 140| -1: [TypeMention] object
11461145
# 140| 0: [VariablePatternExpr] Object y
1146+
# 140| 0: [TypeMention] object
11471147
# 140| 1: [IsExpr] ... is ...
11481148
# 140| 0: [LocalVariableAccess] access to local variable y
11491149
# 140| 1: [RecursivePatternExpr] { ... }

csharp/ql/test/library-tests/definitions/PrintAst.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ definitions.cs:
204204
# 86| 0: [TypeMention] Exception
205205
# 87| 1: [BlockStmt] {...}
206206
# 88| 0: [ForeachStmt] foreach (... ... in ...) ...
207-
# 88| -1: [TypeMention] S1
208207
# 88| 0: [LocalVariableDeclExpr] S1 s
208+
# 88| 0: [TypeMention] S1
209209
# 88| 1: [ParameterAccess] access to parameter ss
210210
# 89| 2: [BlockStmt] {...}
211211
# 92| 1: [LocalVariableDeclStmt] ... ...;
@@ -507,18 +507,18 @@ definitions.cs:
507507
# 210| 1: [NullLiteral] null
508508
# 211| 1: [IfStmt] if (...) ...
509509
# 211| 0: [IsExpr] ... is ...
510-
# 211| -1: [TypeMention] C8
511510
# 211| 0: [LocalVariableAccess] access to local variable c8a
512511
# 211| 1: [VariablePatternExpr] C8 c8b
512+
# 211| 0: [TypeMention] C8
513513
# 212| 1: [ExprStmt] ...;
514514
# 212| 0: [AssignExpr] ... = ...
515515
# 212| 0: [LocalVariableAccess] access to local variable c8a
516516
# 212| 1: [LocalVariableAccess] access to local variable c8b
517517
# 213| 2: [SwitchStmt] switch (...) {...}
518518
# 213| 0: [LocalVariableAccess] access to local variable c8a
519519
# 215| 0: [CaseStmt] case ...:
520-
# 215| -1: [TypeMention] C8
521520
# 215| 0: [VariablePatternExpr] C8 c8c
521+
# 215| 0: [TypeMention] C8
522522
# 215| 1: [NEExpr] ... != ...
523523
# 215| 0: [LocalVariableAccess] access to local variable c8c
524524
# 215| 1: [NullLiteral] null

csharp/ql/test/library-tests/linq/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ queries.cs:
151151
# 39| -1: [TypeMention] IEnumerable<Object>
152152
# 39| 0: [LocalVariableAccess] access to local variable list8
153153
# 41| 1: [MethodCall] call to method Select
154-
# 40| -1: [TypeMention] object
155154
# 40| 0: [LocalVariableDeclAndInitExpr] Object a = ...
155+
# 40| -1: [TypeMention] object
156156
# 40| 0: [LocalVariableAccess] access to local variable a
157157
# 40| 1: [LocalVariableAccess] access to local variable list7
158158
# 41| 1: [LocalVariableAccess] access to local variable a
@@ -176,8 +176,8 @@ queries.cs:
176176
# 49| -1: [TypeMention] IEnumerable<String>
177177
# 49| 0: [LocalVariableAccess] access to local variable list11
178178
# 51| 1: [MethodCall] call to method Select
179-
# 50| -1: [TypeMention] string
180179
# 50| 0: [LocalVariableDeclAndInitExpr] String a = ...
180+
# 50| -1: [TypeMention] string
181181
# 50| 0: [LocalVariableAccess] access to local variable a
182182
# 50| 1: [LocalVariableAccess] access to local variable list7
183183
# 51| 1: [LocalVariableAccess] access to local variable a

csharp/ql/test/library-tests/methods/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ methods.cs:
324324
# 126| 2: [StringLiteral] "333"
325325
# 126| 3: [StringLiteral] "4444"
326326
# 127| 1: [ForeachStmt] foreach (... ... in ...) ...
327-
# 127| -1: [TypeMention] string
328327
# 127| 0: [LocalVariableDeclExpr] String s
328+
# 127| 0: [TypeMention] string
329329
# 127| 1: [MethodCall] call to method Slice
330330
# 127| -1: [LocalVariableAccess] access to local variable strings
331331
# 127| 0: [IntLiteral] 1

csharp/ql/test/library-tests/statements/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ statements.cs:
358358
# 140| 1: [TypeMention] string
359359
# 141| 4: [BlockStmt] {...}
360360
# 142| 0: [ForeachStmt] foreach (... ... in ...) ...
361-
# 142| -1: [TypeMention] string
362361
# 142| 0: [LocalVariableDeclExpr] String s
362+
# 142| 0: [TypeMention] string
363363
# 142| 1: [ParameterAccess] access to parameter args
364364
# 143| 2: [BlockStmt] {...}
365365
# 144| 0: [ExprStmt] ...;
@@ -502,8 +502,8 @@ statements.cs:
502502
# 193| -1: [TypeMention] Void
503503
# 194| 4: [BlockStmt] {...}
504504
# 195| 0: [ForeachStmt] foreach (... ... in ...) ...
505-
# 195| -1: [TypeMention] int
506505
# 195| 0: [LocalVariableDeclExpr] Int32 x
506+
# 195| 0: [TypeMention] int
507507
# 195| 1: [MethodCall] call to method Range
508508
# 195| 0: [UnaryMinusExpr] -...
509509
# 195| 0: [IntLiteral] 10

0 commit comments

Comments
 (0)