Using enum constant from different modules
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 10 13:48:00 PDT 2014
On Thursday, 10 July 2014 at 20:27:39 UTC, Jacob Carlborg wrote:
> Here's a code example:
>
> module main;
>
> import foo;
>
> enum Get = "GET";
>
> void bar (string a)
> {
> assert(a is Get);
> }
>
> void main ()
> {
> asd();
> }
>
> module foo;
>
> import main;
>
> void asd()
> {
> bar(Get);
> }
>
> Running the above code will cause an assert error in the
> function "bar". But if I move the function "asd" into the
> "main" module and completely skip the "foo" module the assert
> passes.
>
> I don't know if I'm thinking completely wrong here but this
> seems like a bug to me.
I don't think this is a bug.
Remember that enums have copy-paste semantics. So, this is the
same as comparing literals from different modules. Apparently, in
the same module, a duplicate string literal is optimized out. But
that's not done across the module boundary. I'd guess that's
because of the separate compilation model.
More information about the Digitalmars-d-learn
mailing list