Hi,
I'm trying to update std.typecons.Unique. I want to add a static opCall with no arguments to simulate a nullary-argument constructor. Unfortunately, with a recent dmd from Git, I get this (reduced code):

class Class {}

struct U
{
    Class c;

    this(A...)(A args)
    if (A.length != 0)
    {
        c = new Class(args);
    }

    static U opCall()
    {
        U u;
        u.c = new Class;
        return u;
    }
}

$ c:\git\digger\current\bin\dmd -w -c "opcall.d" -g -gc -unittest
opcall.d(24): Error: struct opcall.U static opCall is hidden by constructors and can never be called opcall.d(24): Please use a factory method instead, or replace all constructors with static opCall.

This is a new error in the next release. It seems to be this bug, marked as WONTFIX:
https://issues.dlang.org/show_bug.cgi?id=12194

As nullary static opCall doesn't conflict with a nullary constructor (as the latter can't exist), it would be useful to allow it. Otherwise, how can we wrap the construction of a class with a nullary constructor?

Reply via email to