what is special about unittest constants

Dan dbdavidson at yahoo.com
Fri Feb 8 12:12:39 PST 2013


This constant in a module causes a compilation error of the 
"non-constant expression" variety.

DEFINITION 1
   const(AssetProjectionMap) SavingsGrowth2013 = [
     AssetReturnType.Interest :
     RateCurve([DateRate(Date.min, CcRate(0.007))]),
   ];

The fix that addresses this error at module level is:

DEFINITION 2

const(AssetProjectionMap) SavingsGrowth2013;
static this() {
   SavingsGrowth2013 = [
     AssetReturnType.Interest :
     RateCurve([DateRate(Date.min, CcRate(0.007))]),
   ];
}


However, the same constant, when defined in a unittest block 
works with DEFINITION 1. What is the reason for the difference 
between unittest constants and module constants?

Thanks,
Dan


More information about the Digitalmars-d-learn mailing list