Search code examples
d

Undefined identifier error with enum in the separate module


I am having troubles to use the enum defined in the separate module. When I try to access it, I am getting "Undefined identifier" error:

// CodeEnum.d

enum CodeEnum
{
    OK = 200,
    FAIL = 400
}

unittest
{
    auto e = CodeEnum.OK; // Works!
}

-

// Reply.d

import CodeEnum;

unittest
{
    auto.e = CodeEnum.OK; // Error: undefined identifier 'OK'
}

What am I doing wrong?

By the way, I've also posted this to the digitalmars-d-learn, but I don't see my email anywhere on the internet (list archive or forum) - is the list moderated in some way?


Solution

  • Since the module is called CodeEnum, CodeEnum.OK refers to a symbol OK in the module CodeEnum.

    Use CodeEnum.CodeEnum.OK, or use a selective import: import CodeEnum: CodeEnum;, or give the module or the enum a different name.