Thread overview
[Issue 2704] Constness lost when passing a struct member by alias
Sep 17, 2019
RazvanN
Sep 17, 2019
Max Samukha
Sep 17, 2019
RazvanN
Dec 17, 2022
Iain Buclaw
September 17, 2019
https://issues.dlang.org/show_bug.cgi?id=2704

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
I think that passing a runtime variable to an alias parameter should be an error.

--
September 17, 2019
https://issues.dlang.org/show_bug.cgi?id=2704

Max Samukha <maxsamukha@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxsamukha@gmail.com

--- Comment #2 from Max Samukha <maxsamukha@gmail.com> ---
Would that break tons of reflective code like this?

// any template extracting compile-time info
template hasAttr(alias symbol, alias attr) {
        import std.meta;
        enum _f(alias s) = __traits(isSame, s, attr);
        alias hasAttr = anySatisfy!(_f, __traits(getAttributes, symbol));
}

struct attr {
}

int main() {
        @attr int x;
        static assert(hasAttr!(x, attr)); // wouldn't work anymore
        return 0;
}

--
September 17, 2019
https://issues.dlang.org/show_bug.cgi?id=2704

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Max Samukha from comment #2)
> Would that break tons of reflective code like this?
> 
> // any template extracting compile-time info
> template hasAttr(alias symbol, alias attr) {
> 	import std.meta;
> 	enum _f(alias s) = __traits(isSame, s, attr);
> 	alias hasAttr = anySatisfy!(_f, __traits(getAttributes, symbol));
> }
> 
> struct attr {
> }
> 
> int main() {
> 	@attr int x;
> 	static assert(hasAttr!(x, attr)); // wouldn't work anymore
> 	return 0;
> }

Yes. I tried working out a particular solution where only dotId expressions (such as the one on the original bug report) are excluded if the member is not a static one and it still breaks code in the dmd testsuite. It really is a rats nest.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=2704

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--