Why this fails when using unittest?

Machine Code jckj33 at gmail.com
Thu Jun 6 17:49:35 UTC 2019


On Thursday, 6 June 2019 at 17:40:17 UTC, Machine Code wrote:
> outside an unittest, this compiles fine:
>
> 	struct A
> 	{
> 		enum A foo = "hehe";
> 		this(string a) { m_a = a; }
> 		alias m_a this;
> 		string m_a;
> 	}
>
> but if you wrap this a unittest {} and compile with
>> dmd -unittest -run foo.d
>
> this give the following error:
>
>> 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.

I this notice albeit a simple cast workaround that:

> enum A foo = cast(A)"hehe";

or better:

> enum foo = A("hehe");

but isn't that a bug? what am I missing?


More information about the Digitalmars-d-learn mailing list