Skip to content

Commit b4da63b

Browse files
authored
Merge pull request github#2061 from hvitved/csharp/local-function-label
C#: Prepend enclosing method in local function TRAP labels
2 parents e048207 + 413926f commit b4da63b

File tree

8 files changed

+17
-6
lines changed

8 files changed

+17
-6
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ class LocalFunction : Method
1111
{
1212
}
1313

14+
Method ContainingMethod =>
15+
symbol.OriginalDefinition.ContainingSymbol is IMethodSymbol m
16+
? Method.Create(Context, m)
17+
: throw new InternalError(symbol, "Unable to determine local function's containing callable");
18+
1419
public override void WriteId(TextWriter trapFile)
1520
{
21+
trapFile.WriteSubId(ContainingMethod);
22+
trapFile.Write(".(");
1623
trapFile.WriteSubId(Location);
24+
trapFile.Write(')');
1725
if (symbol.IsGenericMethod && !IsSourceDeclaration)
1826
{
1927
trapFile.Write('<');
@@ -41,7 +49,7 @@ public override void Populate(TextWriter trapFile)
4149
// the "static" modifier is present.
4250
if (symbol.DeclaringSyntaxReferences.SingleOrDefault().GetSyntax() is LocalFunctionStatementSyntax fn)
4351
{
44-
foreach(var modifier in fn.Modifiers)
52+
foreach (var modifier in fn.Modifiers)
4553
{
4654
Modifier.HasModifier(Context, trapFile, this, modifier.Text);
4755
}

csharp/ql/test/library-tests/csharp7/CSharp7.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Generics()
162162

163163
U h<T, U>(T t, U u)
164164
{
165-
int f2() => f<T>();
165+
int f2<S>(S s, T _t) => f<T>();
166166
f<T>();
167167
return g(u);
168168
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| CSharp7.cs:152:13:152:26 | f9 | CSharp7.cs:152:25:152:25 | 0 |
1313
| CSharp7.cs:160:9:160:24 | f | CSharp7.cs:160:23:160:23 | 1 |
1414
| CSharp7.cs:161:9:161:25 | g | CSharp7.cs:161:24:161:24 | access to parameter t |
15-
| CSharp7.cs:165:13:165:31 | f2 | CSharp7.cs:165:25:165:30 | call to local function f |
15+
| CSharp7.cs:165:13:165:43 | f2 | CSharp7.cs:165:37:165:42 | call to local function f |
1616
| CSharp7.cs:177:9:177:40 | f | CSharp7.cs:177:31:177:39 | ... + ... |
1717
| CSharp7.cs:178:9:178:32 | g | CSharp7.cs:178:31:178:31 | access to parameter s |
1818
| CSharp7.cs:284:32:284:61 | (...) => ... | CSharp7.cs:284:40:284:61 | (..., ...) |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
| CSharp7.cs:147:30:147:34 | call to local function f7 | CSharp7.cs:143:9:143:31 | f7 | CSharp7.cs:143:9:143:31 | f7 |
44
| CSharp7.cs:148:20:148:24 | call to local function f9 | CSharp7.cs:147:13:147:35 | f9 | CSharp7.cs:147:13:147:35 | f9 |
55
| CSharp7.cs:155:16:155:20 | call to local function f1 | CSharp7.cs:131:9:131:39 | f1 | CSharp7.cs:131:9:131:39 | f1 |
6-
| CSharp7.cs:165:25:165:30 | call to local function f | CSharp7.cs:160:9:160:24 | f | CSharp7.cs:160:9:160:24 | f |
6+
| CSharp7.cs:165:37:165:42 | call to local function f | CSharp7.cs:160:9:160:24 | f | CSharp7.cs:160:9:160:24 | f |
77
| CSharp7.cs:166:13:166:18 | call to local function f | CSharp7.cs:160:9:160:24 | f | CSharp7.cs:160:9:160:24 | f |
88
| CSharp7.cs:167:20:167:23 | call to local function g | CSharp7.cs:161:9:161:25 | g | CSharp7.cs:161:9:161:25 | g |
99
| CSharp7.cs:170:9:170:15 | call to local function h | CSharp7.cs:163:9:168:9 | h | CSharp7.cs:163:9:168:9 | h |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
| CSharp7.cs:163:9:168:9 | h | 1 | CSharp7.cs:163:26:163:26 | u | Boolean |
1313
| CSharp7.cs:163:9:168:9 | h | 1 | CSharp7.cs:163:26:163:26 | u | Int32 |
1414
| CSharp7.cs:163:9:168:9 | h | 1 | CSharp7.cs:163:26:163:26 | u | U |
15+
| CSharp7.cs:165:13:165:43 | f2 | 0 | CSharp7.cs:165:25:165:25 | s | S |
16+
| CSharp7.cs:165:13:165:43 | f2 | 1 | CSharp7.cs:165:30:165:31 | _t | T |
1517
| CSharp7.cs:177:9:177:40 | f | 0 | CSharp7.cs:177:25:177:25 | s | String |
1618
| CSharp7.cs:178:9:178:32 | g | 0 | CSharp7.cs:178:25:178:25 | s | String |
1719
| CSharp7.cs:179:9:179:40 | h | 0 | CSharp7.cs:179:25:179:25 | s | String |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| CSharp7.cs:160:9:160:24 | f(...) | CSharp7.cs:160:9:160:24 | f |
1010
| CSharp7.cs:161:9:161:25 | g(...) | CSharp7.cs:161:9:161:25 | g |
1111
| CSharp7.cs:163:9:168:9 | h(...) | CSharp7.cs:163:9:168:9 | h |
12-
| CSharp7.cs:165:13:165:31 | f2(...) | CSharp7.cs:165:13:165:31 | f2 |
12+
| CSharp7.cs:165:13:165:43 | f2(...) | CSharp7.cs:165:13:165:43 | f2 |
1313
| CSharp7.cs:177:9:177:40 | f(...) | CSharp7.cs:177:9:177:40 | f |
1414
| CSharp7.cs:178:9:178:32 | g(...) | CSharp7.cs:178:9:178:32 | g |
1515
| CSharp7.cs:179:9:179:40 | h(...) | CSharp7.cs:179:9:179:40 | h |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
| CSharp7.cs:163:9:168:9 | h | h | Boolean | CSharp7.cs:159:5:172:5 | {...} | CSharp7.cs:163:9:168:9 | h(...) | h(string, bool) |
1414
| CSharp7.cs:163:9:168:9 | h | h | Int32 | CSharp7.cs:159:5:172:5 | {...} | CSharp7.cs:163:9:168:9 | h(...) | h(int, int) |
1515
| CSharp7.cs:163:9:168:9 | h | h | U | CSharp7.cs:159:5:172:5 | {...} | CSharp7.cs:163:9:168:9 | h(...) | h(T, U) |
16-
| CSharp7.cs:165:13:165:31 | f2 | f2 | Int32 | CSharp7.cs:164:9:168:9 | {...} | CSharp7.cs:165:13:165:31 | f2(...) | f2() |
16+
| CSharp7.cs:165:13:165:43 | f2 | f2 | Int32 | CSharp7.cs:164:9:168:9 | {...} | CSharp7.cs:165:13:165:43 | f2(...) | f2(S, T) |
1717
| CSharp7.cs:177:9:177:40 | f | f | String | CSharp7.cs:175:5:184:5 | {...} | CSharp7.cs:177:9:177:40 | f(...) | f(string) |
1818
| CSharp7.cs:178:9:178:32 | g | g | String | CSharp7.cs:175:5:184:5 | {...} | CSharp7.cs:178:9:178:32 | g(...) | g(string) |
1919
| CSharp7.cs:179:9:179:40 | h | h | String | CSharp7.cs:175:5:184:5 | {...} | CSharp7.cs:179:9:179:40 | h(...) | h(string) |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
| CSharp7.cs:161:9:161:25 | g | 0 | CSharp7.cs:161:13:161:13 | T |
55
| CSharp7.cs:163:9:168:9 | h | 0 | CSharp7.cs:163:13:163:13 | T |
66
| CSharp7.cs:163:9:168:9 | h | 1 | CSharp7.cs:163:16:163:16 | U |
7+
| CSharp7.cs:165:13:165:43 | f2 | 0 | CSharp7.cs:165:20:165:20 | S |

0 commit comments

Comments
 (0)