Why this fails when using unittest?

Steven Schveighoffer schveiguy at gmail.com
Thu Jun 6 21:02:37 UTC 2019


On 6/6/19 1:49 PM, Adam D. Ruppe wrote:
> On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote:
>> outside an unittest, this compiles fine:
>>
>>     struct A
> 
> try making it `static struct` instead
> 
> 
>>> cannot implicitly convert expression "hehe" of type string to A
>>
>> Why does inside a unittest it doesn't work? the constructor 
>> this(string) {} seems to get disabled.
> 
> My suspicion is it is trying to access the context of the unittest as a 
> hidden paramater to that constructor there... and in an enum, it can't, 
> just stupid compiler didn't think to mention the hidden arg here.
> 
> my guess.

Yes, correct guess. A unittest block is actually a function, so it's 
considered an inner struct with a hidden context pointer.

-Steve


More information about the Digitalmars-d-learn mailing list