www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19047] New: Undefined identifier caused by circular import


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

3 modules are involved:

=== ast.d ===

module ast;

import symbol;

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


alias AstNodes = AstNodesSeq;

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

class AstNode{}

=== utils.d ====

module utils;

import ast, symbol;

class Foo

=== 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)

Jul 02 2018