digitalmars.D.learn - error initializing an immutable struct member with a function that
- aliak (22/22) Oct 21 2018 Hi,
Hi, The code below fails with "Error: delegate `onlineapp.A!int.A.__dgliteral2` cannot be struct members": T f(T)(lazy T value) { return value; } struct A(T) { immutable a = f("hi"); } void main() { A!int i; } Removing the lazy keyword fixes the error. But I'm wondering if I can keep lazy there. Is this a compile bug perhaps? The actual use case where this is causing a problem is from this function: https://github.com/aliak00/ddash/blob/5c9f2923028c7c16b89b041b399f6fb1bc73639c/range/source/ddash/range/front.d#L25 and needing to use it in a declaration scope of a struct in this kind of way: struct A(string name) { immutable firstPart = name.split("|").frontOr(""); } Cheers, -Ali
Oct 21 2018