Skip to content

Conversation

@michaelnebel
Copy link
Contributor

In this PR we add a test for nameof applied to a generic type (previously this only worked for constructed types). This works out of the box in the extractor and QL library.

@github-actions github-actions bot added the C# label Jan 6, 2026
@michaelnebel michaelnebel marked this pull request as ready for review January 6, 2026 10:54
@michaelnebel michaelnebel requested a review from a team as a code owner January 6, 2026 10:54
Copilot AI review requested due to automatic review settings January 6, 2026 10:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a comprehensive test for the C# 14 feature that allows nameof to be applied to generic types, including unconstructed generic types. The test confirms that the extractor and QL library handle this feature correctly out of the box.

  • Adds a new test directory for nameof operator testing
  • Tests various uses of nameof including parameters, methods, types, and generic types
  • Specifically validates the new capability to use nameof(List<>) for unconstructed generic types

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
csharp/ql/test/library-tests/nameof/NameOf.cs C# source file with 6 test cases for nameof, including the new unconstructed generic type usage
csharp/ql/test/library-tests/nameof/nameof.ql QL query to extract and test NameOfExpr instances
csharp/ql/test/library-tests/nameof/nameof.expected Expected results showing all 6 nameof expressions and their accessed elements
csharp/ql/test/library-tests/nameof/PrintAst.qlref Reference to shared PrintAst query for AST validation
csharp/ql/test/library-tests/nameof/PrintAst.expected Expected AST output showing the structure of all test cases
csharp/ql/test/library-tests/nameof/options Extractor configuration options for the test

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


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.
{
public void M(int x)
{
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.
public void M(int x)
{
var test1 = nameof(x);
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 test1 = nameof(x);
var test2 = nameof(M);
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 test1 = nameof(x);
var test2 = nameof(M);
var test3 = nameof(Program);
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 test2 = nameof(M);
var test3 = nameof(Program);
var test4 = nameof(String);
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 test3 = nameof(Program);
var test4 = nameof(String);
var test5 = nameof(List<int>);
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.
@michaelnebel michaelnebel merged commit f32860b into github:main Jan 6, 2026
24 checks passed
@michaelnebel michaelnebel deleted the csharp14/nameofgenerictype branch January 6, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants