-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C# 14: [TEST ONLY] Test for nameof generic type.
#21100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# 14: [TEST ONLY] Test for nameof generic type.
#21100
Conversation
There was a problem hiding this 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
nameofoperator testing - Tests various uses of
nameofincluding 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) |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| { | ||
| public void M(int x) | ||
| { | ||
| var test1 = nameof(x); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
| public void M(int x) | ||
| { | ||
| var test1 = nameof(x); | ||
| var test2 = nameof(M); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
| var test2 = nameof(M); | |
| nameof(M); |
| { | ||
| var test1 = nameof(x); | ||
| var test2 = nameof(M); | ||
| var test3 = nameof(Program); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
| var test1 = nameof(x); | ||
| var test2 = nameof(M); | ||
| var test3 = nameof(Program); | ||
| var test4 = nameof(String); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
| var test2 = nameof(M); | ||
| var test3 = nameof(Program); | ||
| var test4 = nameof(String); | ||
| var test5 = nameof(List<int>); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
| var test3 = nameof(Program); | ||
| var test4 = nameof(String); | ||
| var test5 = nameof(List<int>); | ||
| var test6 = nameof(List<>); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
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.
In this PR we add a test for
nameofapplied to a generic type (previously this only worked for constructed types). This works out of the box in the extractor and QL library.