Skip to content
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
15 changes: 15 additions & 0 deletions csharp/ql/test/library-tests/nameof/NameOf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;

class Program
{
public void M(int x)
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local scope variable 'x' shadows Program.x.
Local scope variable 'x' shadows Program.x.

Copilot uses AI. Check for mistakes.
{
var test1 = nameof(x);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test1 is useless, since its value is never read.

Copilot uses AI. Check for mistakes.
var test2 = nameof(M);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test2 is useless, since its value is never read.

Suggested change
var test2 = nameof(M);
nameof(M);

Copilot uses AI. Check for mistakes.
var test3 = nameof(Program);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test3 is useless, since its value is never read.

Copilot uses AI. Check for mistakes.
var test4 = nameof(String);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test4 is useless, since its value is never read.

Copilot uses AI. Check for mistakes.
var test5 = nameof(List<int>);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test5 is useless, since its value is never read.

Copilot uses AI. Check for mistakes.
var test6 = nameof(List<>);
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to test6 is useless, since its value is never read.

Copilot uses AI. Check for mistakes.
}
}
50 changes: 50 additions & 0 deletions csharp/ql/test/library-tests/nameof/PrintAst.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
NameOf.cs:
# 4| [Class] Program
# 6| 6: [Method] M
# 6| -1: [TypeMention] Void
#-----| 2: (Parameters)
# 6| 0: [Parameter] x
# 6| -1: [TypeMention] int
# 7| 4: [BlockStmt] {...}
# 8| 0: [LocalVariableDeclStmt] ... ...;
# 8| 0: [LocalVariableDeclAndInitExpr] String test1 = ...
# 8| -1: [TypeMention] string
# 8| 0: [LocalVariableAccess] access to local variable test1
# 8| 1: [NameOfExpr] nameof(...)
# 8| 0: [ParameterAccess] access to parameter x
# 9| 1: [LocalVariableDeclStmt] ... ...;
# 9| 0: [LocalVariableDeclAndInitExpr] String test2 = ...
# 9| -1: [TypeMention] string
# 9| 0: [LocalVariableAccess] access to local variable test2
# 9| 1: [NameOfExpr] nameof(...)
# 9| 0: [MethodAccess] access to method M
# 10| 2: [LocalVariableDeclStmt] ... ...;
# 10| 0: [LocalVariableDeclAndInitExpr] String test3 = ...
# 10| -1: [TypeMention] string
# 10| 0: [LocalVariableAccess] access to local variable test3
# 10| 1: [NameOfExpr] nameof(...)
# 10| 0: [TypeAccess] access to type Program
# 10| 0: [TypeMention] Program
# 11| 3: [LocalVariableDeclStmt] ... ...;
# 11| 0: [LocalVariableDeclAndInitExpr] String test4 = ...
# 11| -1: [TypeMention] string
# 11| 0: [LocalVariableAccess] access to local variable test4
# 11| 1: [NameOfExpr] nameof(...)
# 11| 0: [TypeAccess] access to type String
# 11| 0: [TypeMention] string
# 12| 4: [LocalVariableDeclStmt] ... ...;
# 12| 0: [LocalVariableDeclAndInitExpr] String test5 = ...
# 12| -1: [TypeMention] string
# 12| 0: [LocalVariableAccess] access to local variable test5
# 12| 1: [NameOfExpr] nameof(...)
# 12| 0: [TypeAccess] access to type List<Int32>
# 12| 0: [TypeMention] List<int>
# 12| 1: [TypeMention] int
# 13| 5: [LocalVariableDeclStmt] ... ...;
# 13| 0: [LocalVariableDeclAndInitExpr] String test6 = ...
# 13| -1: [TypeMention] string
# 13| 0: [LocalVariableAccess] access to local variable test6
# 13| 1: [NameOfExpr] nameof(...)
# 13| 0: [TypeAccess] access to type List`1
# 13| 0: [TypeMention] List<T>
# 13| 1: [TypeMention] T
1 change: 1 addition & 0 deletions csharp/ql/test/library-tests/nameof/PrintAst.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shared/PrintAst.ql
6 changes: 6 additions & 0 deletions csharp/ql/test/library-tests/nameof/nameof.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| NameOf.cs:8:21:8:29 | nameof(...) | NameOf.cs:8:28:8:28 | access to parameter x |
| NameOf.cs:9:21:9:29 | nameof(...) | NameOf.cs:9:28:9:28 | access to method M |
| NameOf.cs:10:21:10:35 | nameof(...) | NameOf.cs:10:28:10:34 | access to type Program |
| NameOf.cs:11:21:11:34 | nameof(...) | NameOf.cs:11:28:11:33 | access to type String |
| NameOf.cs:12:21:12:37 | nameof(...) | NameOf.cs:12:28:12:36 | access to type List<Int32> |
| NameOf.cs:13:21:13:34 | nameof(...) | NameOf.cs:13:28:13:33 | access to type List`1 |
4 changes: 4 additions & 0 deletions csharp/ql/test/library-tests/nameof/nameof.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import csharp

from NameOfExpr e
select e, e.getAccess()
2 changes: 2 additions & 0 deletions csharp/ql/test/library-tests/nameof/options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
semmle-extractor-options: /nostdlib /noconfig
semmle-extractor-options: --load-sources-from-project:${testdir}/../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj