Bug 24301 – [REG 2.100] Misleading error message when passing non-copyable struct by value in @safe code

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-12-25T18:26:18Z
Last change time
2023-12-25T22:28:29Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2023-12-25T18:26:18Z
As of DMD 2.106.0, when attempting to compile the following program: --- struct S { @disable this(ref S); } @safe void fun(S) {} @safe void main() { S s; fun(s); } --- ...the following error message is produced: --- bug.d(11): Error: function `bug.fun(S __param_0)` is not callable using argument types `(S)` bug.d(11): `ref S(ref S)` copy constructor cannot be called from a `@safe` context --- This message is misleading. The reason the copy constructor cannot be called is that it is marked with @disable, and has nothing to do with @safe. According to run.dlang.io, this misleading message was introduced between DMD 2.099.1 and 2.100.2: 2.086.1 to 2.099.1: Failure with output: ----- onlineapp.d(11): Error: function `onlineapp.fun(S _param_0)` is not callable using argument types `(S)` onlineapp.d(11): `struct S` does not define a copy constructor for `S` to `S` copies ----- 2.100.2 to 2.103.1: Failure with output: ----- onlineapp.d(11): Error: function `onlineapp.fun(S _param_0)` is not callable using argument types `(S)` onlineapp.d(11): `ref S(ref S)` copy constructor cannot be called from a `@safe` context -----
Comment #1 by snarwin+bugzilla — 2023-12-25T19:36:01Z
Comment #2 by dlang-bot — 2023-12-25T19:48:21Z
@pbackus created dlang/dmd pull request #15953 "Fix 24301 - Misleading error message when passing non-copyable struct…" fixing this issue: - Fix 24301 - Misleading error message when passing non-copyable struct by value in @safe code If a copy constructor is explicitly marked with @disable, the error message should mention that, regardless of whether its attributes are allowed in the calling scope. https://github.com/dlang/dmd/pull/15953
Comment #3 by dlang-bot — 2023-12-25T22:28:29Z
dlang/dmd pull request #15953 "Fix 24301 - Misleading error message when passing non-copyable struct…" was merged into master: - 1f8dc2b365e41d3fdfc20a6be5b439e92c97f3b5 by Paul Backus: Fix 24301 - Misleading error message when passing non-copyable struct by value in @safe code If a copy constructor is explicitly marked with @disable, the error message should mention that, regardless of whether its attributes are allowed in the calling scope. https://github.com/dlang/dmd/pull/15953