www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24301] New: [REG 2.100] Misleading error message when passing

https://issues.dlang.org/show_bug.cgi?id=24301

          Issue ID: 24301
           Summary: [REG 2.100] Misleading error message when passing
                    non-copyable struct by value in  safe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

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

--
Dec 25 2023