D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3364 - module with unittest forces entire import chain
Summary: module with unittest forces entire import chain
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-10-05 05:59 UTC by anonymous4
Modified: 2019-08-10 18:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description anonymous4 2009-10-05 05:59:32 UTC
This bug forces link of any module that indirectly imports any module with unittest (nearly ANY module) even when I compile without -unittest switch. It forced me to link in a module working with registry, thus forcing dependency on extra library advapi32.dll even when I didn't use anything from that module, this just killed me.

I'm not sure whether this is one bug or two, but together they are fearful.


test.d
---
import test2;

int main()
{
	return 0;
}
---


test2.d
---
module test2;
import test3;
---


test3.d
---
module test3;
import test4;

extern void Foo();

void Goo()
{
	switch("c")
	{
		case "a": break; //comment this line
		case "b": break;
		case "c": break;
		case "d": break;
		default: break;
	}
	Foo();
}
---


test4.d
---
module test4;
unittest
{
}
---

As you see, the main module does basically nothing, everything compiles, but doesn't link. First I tried this command.

>dmd test.d -oftest.exe
OPTLINK (R) for Win32  Release 8.00.1
Copyright (C) Digital Mars 1989-2004  All rights reserved.
test.obj(test)
 Error 42: Symbol Undefined _D5test212__ModuleInfoZ
--- errorlevel 1

It clearly misses test2 module. But why? test2 is nearly empty, there's nothing to link from there! Linker doesn't calm down until you compile and link all 4 modules. Then...

>dmd test.d test2.d test3.d test4.d -oftest.exe
OPTLINK (R) for Win32  Release 8.00.1
Copyright (C) Digital Mars 1989-2004  All rights reserved.
test.obj(test)
 Error 42: Symbol Undefined _D5test33FooFZv
--- errorlevel 1

Now comment case "a" line in test3 and it links. I don't understand, why.
Comment 1 anonymous4 2009-10-05 06:04:16 UTC
dmd test.d -oftest.exe
must link the testcase because there's nothing to link from other modules.
Comment 2 Mathias LANG 2019-08-10 18:39:58 UTC
This test case now compiles successfully.