Fix Unexpected ctor storing error value#8
Merged
tchaloupka merged 1 commit intoMay 18, 2026
Conversation
`this.error = error` referenced the field itself, not the `value` parameter — so the error was never stored, and newer compilers warn: "Deprecation: cannot initialize field `error` with itself". Forward `value` to the field instead, and drop the now-redundant `forward!value` from the super call (it's only reached when T is assignable to string, i.e. a slice type with no move semantics).
Owner
|
thanks |
Contributor
Author
|
thanks as well for the quick merge @tchaloupka! Can you tag v0.4.1? |
5 tasks
tchaloupka
added a commit
that referenced
this pull request
May 18, 2026
Adds assertions to the "Throw" unittest checking that the error value is actually stored on the thrown Unexpected exception, for both the string and non-string error types. This reproduces the self-assignment bug fixed in #8: without that fix the new assertions fail at the `ex.error == ...` checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
Unexpectedexception constructor atsource/expected.d:1312hadthis.error = error;— assigning the field to itself rather than thevalueparameter. As a result, the error value was never actually stored on the exception.Newer compilers now emit:
This will eventually become a hard error.
Fix
I also dropped the
forward!valuefrom thesuper(...)call. Otherwise we'd be forwardingvaluetosuperand tothis.error, which would usevalueafter a potential move. Thestatic ifbranch only fires whenTis assignable tostring(slice types — no meaningful move semantics), so passingvalueby ref tosuperis safe.Test plan
dub test— 43/43 passdub build— clean, no deprecation