Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 20, 2025

Summary

This PR updates the documentation for System.Diagnostics.Contracts.PureAttribute to clarify that the CA1806 code analyzer enforces this attribute.

Changes

The previous documentation stated:

This attribute is not enforced by the current analysis tools; you should use this attribute only if you are sure that the methods are pure.

This statement is outdated. The CA1806 analyzer does check for the [Pure] attribute and emits diagnostics when methods marked as pure have their return values ignored.

The updated documentation now states:

The CA1806 code analyzer checks for this attribute and emits a diagnostic when the return value of a pure method isn't used.

Context

When a method is marked with [Pure], CA1806 emits the following diagnostic if the return value isn't used:

{0} calls {1} but does not use the value the method returns. Because {1} is marked as a Pure method, it cannot have side effects. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method.

This change helps developers understand that applying the [Pure] attribute has practical effects in modern code analysis tooling.

Fixes #(issue number from dotnet/docs repository)

Original prompt

This section details on the original issue you should resolve

<issue_title>Mention this analyzer also checks for the [Pure] attribute</issue_title>
<issue_description>### Type of issue

Typo

Description

CA1806 emits the following diagnostic for [Pure] methods:

{0} calls {1} but does not use the value the method returns. Because {1} is marked as a Pure method, it cannot have side effects. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method.

It would also be useful to mention this in the PureAttribute docs, since it currently says:

This attribute is not enforced by the current analysis tools; you should use this attribute only if you are sure that the methods are pure.

https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.contracts.pureattribute

Page URL

https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1806

Content source URL

https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/quality-rules/ca1806.md

Document Version Independent Id

59d0b85d-87f3-c4e4-6891-3002e2f60158

Platform Id

a91b8153-7420-d312-601a-b29f874cf8ae

Article author

@gewarren

Metadata

  • ID: 0f51f0a0-29e7-be15-ffdc-ee210cf7ef1c
  • PlatformId: a91b8153-7420-d312-601a-b29f874cf8ae
  • Service: dotnet-fundamentals

Related Issues</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes dotnet/docs#48767


💡 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.

@Copilot Copilot AI changed the title [WIP] Fix documentation for CA1806 related to Pure attribute Update PureAttribute documentation to mention CA1806 analyzer enforcement Oct 20, 2025
@Copilot Copilot AI requested a review from gewarren October 20, 2025 22:30
Copilot finished work on behalf of gewarren October 20, 2025 22:30
@gewarren gewarren marked this pull request as ready for review October 20, 2025 23:47
@gewarren gewarren requested a review from a team as a code owner October 20, 2025 23:47
@gewarren gewarren requested review from Copilot and removed request for a team October 20, 2025 23:47
Copy link

@Copilot 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 updates the documentation for System.Diagnostics.Contracts.PureAttribute to reflect that the CA1806 code analyzer actively enforces this attribute by emitting diagnostics when return values of pure methods are ignored.

Key Changes:

  • Removed outdated statement claiming the attribute is not enforced by analysis tools
  • Added reference to CA1806 analyzer and its diagnostic behavior for [Pure] methods

Copy link
Contributor

Tagging subscribers to this area: @tommcdon

@gewarren gewarren enabled auto-merge (squash) October 20, 2025 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mention this analyzer also checks for the [Pure] attribute

2 participants