[Issue 19047] New: Undefined identifier caused by circular import and CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 2 07:03:22 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19047

          Issue ID: 19047
           Summary: Undefined identifier caused by circular import and
                    CTFE
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

3 modules are involved:

=== ast.d ===

module ast;

import symbol;

string astNodesClasses()
{
    return "alias AstNodesSeq = AstNode;";
}

mixin(astNodesClasses());

alias AstNodes = AstNodesSeq;


string genVisitMethods(string statements)
{
    return "void visit(" ~ AstNodes.stringof ~ "){}";
}

class AstNode{}

=== utils.d ====

module utils;

import ast, symbol;


class Foo
{
    mixin(genVisitMethods(""));
}

=== symbol.d ===

module symbol;

import utils; // circular problem caused by this

================

compile with: 

    `dmd ast.d symbol.d utils.d -lib`

to get: 

    `ast.d(12): Error: undefined identifier AstNodesSeq
    utils.d(8):        called from here: genVisitMethods("")`

Now remove the import in symbol.d and try again, no problem, error is gone.
I think that there's should not be any circular issue.

In bigger project CTFE fails because of this (CTFE fails because of previous
error in genVisit... etc)

--


More information about the Digitalmars-d-bugs mailing list