Skip to content

Commit 423fee3

Browse files
committed
Fix argument location of top level statement entry point
1 parent b79d5ab commit 423fee3

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Parameter.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public override void Populate(TextWriter trapFile)
112112
foreach (var l in symbol.Locations)
113113
trapFile.param_location(this, Context.CreateLocation(l));
114114

115+
if (!symbol.Locations.Any() &&
116+
symbol.ContainingSymbol is IMethodSymbol ms &&
117+
ms.Name == WellKnownMemberNames.TopLevelStatementsEntryPointMethodName)
118+
{
119+
trapFile.param_location(this, Context.CreateLocation());
120+
}
121+
115122
if (!IsSourceDeclaration || !symbol.FromSource())
116123
return;
117124

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ FunctionPointer.cs:
392392
GlobalStmt.cs:
393393
# 7| [Class] <Program>$
394394
# 7| 4: [Method] <Main>$
395+
#-----| 2: (Parameters)
396+
# 1| 0: [Parameter] args
395397
# 7| 4: [BlockStmt] {...}
396398
# 11| 0: [ExprStmt] ...;
397399
# 11| 0: [MethodCall] call to method WriteLine

csharp/ql/test/library-tests/csharp9/globalStmt.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ global_stmt
44
| GlobalStmt.cs:13:1:13:4 | ...; |
55
| GlobalStmt.cs:15:1:17:1 | M(...) |
66
globalBlock
7-
| GlobalStmt.cs:7:1:25:1 | {...} | GlobalStmt.cs:7:1:25:1 | <Main>$ | file://:0:0:0:0 | args | GlobalStmt.cs:7:1:25:1 | <Program>$ |
7+
| GlobalStmt.cs:7:1:25:1 | {...} | GlobalStmt.cs:7:1:25:1 | <Main>$ | GlobalStmt.cs:1:1:1:0 | args | GlobalStmt.cs:7:1:25:1 | <Program>$ |
88
methods
99
| GlobalStmt.cs:7:1:25:1 | <Main>$ | entry |
1010
| GlobalStmt.cs:21:8:21:9 | M1 | non-entry |

0 commit comments

Comments
 (0)