-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix ITypeSymbol.BaseType documentation for type parameters #80770
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
Conversation
Updated the documentation to correctly state that type parameters return null for BaseType, not the effective base class. Added a test to verify this behavior. Co-authored-by: CyrusNajmabadi <[email protected]>
src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs
Outdated
Show resolved
Hide resolved
| { | ||
| // This test verifies that ITypeSymbol.BaseType returns null for type parameters, | ||
| // not the effective base class. | ||
| var source = @" |
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.
@copilot use a raw string literal here. Also, add to the copilot contributing document to prefer raw string literals when creating new tests.
Also, remove the comments here. They're redundant. #Closed
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.
Changed to raw string literal and removed comments. Added raw string literal preference to copilot-instructions.md in commit abc1234.
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.
Changed to raw string literal and removed comments. Added raw string literal preference to copilot-instructions.md in commit a967887.
…ibuting docs
- Changed test to use raw string literal (""") instead of verbatim string (@"")
- Removed redundant comments from test
- Added raw string literal preference to copilot-instructions.md
Co-authored-by: CyrusNajmabadi <[email protected]>
| /// The declared base type of this type, or null. The object type, interface types, | ||
| /// and pointer types do not have a base type. The base type of a type parameter | ||
| /// is its effective base class. | ||
| /// pointer types, and type parameters do not have a base type. |
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.
@copilot can you add tests for the other cases as well in the same vein as the test you added. so 'the object type', 'interface types' and 'pointer types'.
Can you also add a test with a method type parameter as well?
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.
Added tests for all cases in commit [hash]. The new tests cover:
- MethodTypeParameter_BaseType_ReturnsNull: method type parameters
- ObjectType_BaseType_ReturnsNull: System.Object
- InterfaceType_BaseType_ReturnsNull: interface types
- PointerType_BaseType_ReturnsNull: pointer types
All 5 tests pass successfully.
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.
Added tests for all cases in commit e915694. The new tests cover:
- MethodTypeParameter_BaseType_ReturnsNull: method type parameters
- ObjectType_BaseType_ReturnsNull: System.Object
- InterfaceType_BaseType_ReturnsNull: interface types
- PointerType_BaseType_ReturnsNull: pointer types
All 5 tests pass successfully.
Added tests for all cases mentioned in ITypeSymbol.BaseType documentation: - MethodTypeParameter_BaseType_ReturnsNull: Tests method type parameters - ObjectType_BaseType_ReturnsNull: Tests System.Object - InterfaceType_BaseType_ReturnsNull: Tests interface types - PointerType_BaseType_ReturnsNull: Tests pointer types Co-authored-by: CyrusNajmabadi <[email protected]>
|
@dotnet/roslyn-compiler ptal. Given the long standing behavior here, i'm going with the approach of just updating the documentation to match how thigns have worked in roslyn forever. |
| Assert.Equal("Base.Nest", model.GetTypeInfo(nest).Type.ToDisplayString()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78605")] |
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.
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.
Fixed all WorkItem attributes to reference issue #41733 in commit [hash].
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.
Updated all WorkItem attributes in the BaseType tests to point to the correct issue #41733 instead of #78605. Co-authored-by: CyrusNajmabadi <[email protected]>
Updated copilot-instructions.md to include guidance that tests should avoid unnecessary intermediary assertions and do the minimal amount of work to validate just the core issue being addressed. Co-authored-by: CyrusNajmabadi <[email protected]>
| int* ptr; | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugDll); |
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.
@copilot Restore the VerifyEmitDiagnostics() checks on compilations in every test you added. If the compilation had errors (not necessarily trivial for human reviewers to spot) that might cause the behavior observed below (null BaseType) for incorrect reasons.
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.
Restored VerifyDiagnostics() checks to all 5 tests in commit [hash]. Each compilation now verifies it has no errors (or only expected warnings in the pointer test case).
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.
Restored VerifyDiagnostics() checks to all 5 tests in commit 3dd27c2. Each compilation now verifies it has no errors (or only expected warnings in the pointer test case).
Restored VerifyDiagnostics() calls to ensure compilations are error-free in all 5 BaseType tests. For the pointer test, added the expected unreferenced field warning diagnostic. Co-authored-by: jcouv <[email protected]>
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.
LGTM Thanks (commit 9)
| - Language-specific test bases: `CSharpTestBase`, `VisualBasicTestBase` | ||
| - Add `[WorkItem("https://github.com/dotnet/roslyn/issues/issueNumber")]` attribute to tests that fix specific GitHub issues | ||
| - Prefer raw string literals (`"""..."""`) over verbatim strings (`@"..."`) when creating test source code | ||
| - Avoid unnecessary intermediary assertions - tests should do the minimal amount of work to validate just the core issue being addressed |
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.
@copilot. Update this. First, mention that, as an example, using something like 'Single()' can be better than extra statements asserting the length is one and pulling out an element. Second, mention that for compiler tests it is normally good to validate diagnostics. That way a reviewer can easily see if the code is in error, or represents something legal.
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.
Updated copilot-instructions.md with sub-bullets explaining the use of concise methods like Single() and the importance of validating diagnostics in compiler tests in commit [hash].
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.
Updated copilot-instructions.md with sub-bullets explaining the use of concise methods like Single() and the importance of validating diagnostics in compiler tests in commit d2c3a23.
…idance Added sub-bullets to testing conventions explaining: - Use concise methods like Single() instead of asserting count and extracting elements - Always validate diagnostics in compiler tests for reviewer clarity Co-authored-by: CyrusNajmabadi <[email protected]>
Co-authored-by: Rikki Gibson <[email protected]>
* upstream/main: (123 commits) Fix SafeContext of Span-valued collection expressions to match specification (dotnet#80684) Improve detection of invalid references for implicitly typed expression variables declared within implicit object creation expressions. (dotnet#80546) Add test demonstrating behavior of ToMinimalDisplayString. (dotnet#80757) Only set DOTNET_HOST_PATH if something was installed (dotnet#80842) Clean up a Razor external access service (dotnet#80830) Remove unused statement (dotnet#80823) Allow foreach on typed null enumerables (dotnet#80783) Update documentation for DeclaringSyntaxReferences and Locations to clarify partial members behavior (dotnet#80704) Fix issue converting an auto prop to a full prop when 'field' and 'initializers' are involved Rename childIsSimple to innerExpressionHasPrimaryPrecedence and add more test cases Remove placeholder WorkItem attributes from new tests Fix RemoveUnnecessaryParentheses to detect simple expressions in bitwise operations [main] Update dependencies from dotnet/arcade (dotnet#80828) Fix ITypeSymbol.BaseType documentation for type parameters (dotnet#80770) soft-select select camelcase matched item if user might be typing an undefined type parameter (dotnet#80809) Allow semantic tokens in Razor to be better behaved (dotnet#80815) Rebase Remove using Update test Add fix all test ...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.