Skip to content

Conversation

@ntrel
Copy link
Contributor

@ntrel ntrel commented Jan 9, 2026

More permissive version of #21717 (which already found an unintended no-op in libdparse). This allows the assignment if it returns a value which is used, so this doesn't break libmir.
Fixes #21507.

Error only applies when struct has no pointer fields - as a pointer could be written through, making the assignment meaningful. (This could be tightened to also error when there's a pointer field but it's not tail mutable). Note this is required not to break ae.utils.array.list whose opAssign writes through its context pointer.

My plan is to enable this for the 2024 edition, as it potentially can break existing calls of a user-defined op overload which has a (non-pointer) field but mutates a global. That should be a rare case and the compiler suggests workarounds. Note that requiring weak purity (for e.g. opAssign) would mean the error wouldn't detect bug-prone cases that aren't marked/inferred pure.

Error applies when struct has no pointer fields. (This could be
tightened to apply when a pointer field is not tail mutable).

My plan is to enable this for the 2024 edition, as it can break a
user-defined op overload which has a (non-pointer) field but mutates a
global. That should be a rare case and the compiler suggests
workarounds. Note that requiring weak purity (for e.g. `opAssign`) would
mean the error wouldn't detect bug-prone cases that aren't
marked/inferred pure.
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#22369"

ntrel added a commit to ntrel/tools that referenced this pull request Jan 9, 2026
ntrel added a commit to ntrel/tools that referenced this pull request Jan 9, 2026
thewilsonator pushed a commit to dlang/tools that referenced this pull request Jan 9, 2026
@ntrel
Copy link
Contributor Author

ntrel commented Jan 9, 2026

The tests for e36981e showed only 3 projects in buildkite were broken, all due to them depending on older libdparse (which had a real bug). So I've made this require >= 2024 edition to enable the new error as mentioned. I pushed a fix for the C++ header (which CircleCI was failing on).

setError();
}

void setOpOverloadAssign(Expression e)
Copy link
Member

Choose a reason for hiding this comment

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

Need function documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it private and added a comment.

@WalterBright
Copy link
Member

Can you please be clearer about what problem this addresses?

@ntrel
Copy link
Contributor Author

ntrel commented Jan 12, 2026

@WalterBright It detects assignments which have no effect (aside from writing to globals which is rare - I haven't seen any), indicating a bug. In these cases the programmer believes it has an effect - e.g. the libdparse one.

@ntrel ntrel marked this pull request as ready for review January 12, 2026 10:38
@ntrel ntrel requested a review from ibuclaw as a code owner January 12, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling opAssign on an rvalue should be illegal

3 participants