www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - error initializing an immutable struct member with a function that


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 


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("");

Oct 21 2018