Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,34 @@ void FuncDeclaration::toObjFile(int multiobj)
if (!global.params.useUnitTests &&
ti && ti->instantiatingModule && !ti->instantiatingModule->root)
{
//printf("instantiated by %s %s\n", ti->instantiatingModule->toChars(), ti->toChars());
return;
Module *mi = ti->instantiatingModule;

// If mi imports any root modules, we still need to generate the code.
for (size_t i = 0; i < Module::amodules.dim; ++i)
{
Module *m = Module::amodules[i];
m->insearch = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this and later insearch reset are necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circular imports.

}
bool importsRoot = false;
for (size_t i = 0; i < Module::amodules.dim; ++i)
{
Module *m = Module::amodules[i];
if (m->root && mi->imports(m))
{
importsRoot = true;
break;
}
}
for (size_t i = 0; i < Module::amodules.dim; ++i)
{
Module *m = Module::amodules[i];
m->insearch = 0;
}
if (!importsRoot)
{
//printf("instantiated by %s %s\n", ti->instantiatingModule->toChars(), ti->toChars());
return;
}
}

if (global.params.verbose)
Expand Down
7 changes: 7 additions & 0 deletions test/runnable/imports/test11039b.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

module imports.test11039b;

import test11039;

static anotherGlobalField = SomeStruct!string("Hello Again!");

23 changes: 23 additions & 0 deletions test/runnable/test11039.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To compile test11039.d and imports/test11039b.d separately, you need to add // COMPILE_SEPARATELY option here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// COMPILE_SEPARATELY
// EXTRA_SOURCES: imports/test11039b.d

import imports.test11039b;

struct SomeStruct(T)
{
T field;
T getInnerField()
{
return field;
}
}

static globalField = SomeStruct!string("Hello!");

void main()
{
globalField.getInnerField();
anotherGlobalField.getInnerField();
}