D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 461 - Constant not understood to be constant when circular module dependency exists.
Summary: Constant not understood to be constant when circular module dependency exists.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2006-10-25 20:15 UTC by Bradley Smith
Modified: 2014-02-15 13:22 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bradley Smith 2006-10-25 20:15:57 UTC
dmd tmp2.d tmp2b.d
tmp2b.d(6): Integer constant expression expected instead of SIZE
tmp2b.d(6): Integer constant expression expected instead of SIZE

----- tmp2.d -----

private import tmp2b;

const int SIZE = 7;

----- tmp2b.d -----

private import tmp2;

struct s {

    char a[ SIZE ];

}

Workaround:
Move constant above import of other module.

----- tmp2.d -----

const int SIZE = 7;

private import tmp2b;
Comment 1 Thomas Kühne 2006-11-08 09:36:50 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail@puremagic.com schrieb am 2006-10-26:
> http://d.puremagic.com/issues/show_bug.cgi?id=461

> dmd tmp2.d tmp2b.d
> tmp2b.d(6): Integer constant expression expected instead of SIZE
> tmp2b.d(6): Integer constant expression expected instead of SIZE
>
> ----- tmp2.d -----
>
> private import tmp2b;
>
> const int SIZE = 7;
>
> ----- tmp2b.d -----
>
> private import tmp2;
>
> struct s {
>
>     char a[ SIZE ];
>
> }
>
> Workaround:
> Move constant above import of other module.
>
> ----- tmp2.d -----
>
> const int SIZE = 7;
>
> private import tmp2b;

Added to DStress as
http://dstress.kuehne.cn/compile/c/const_40_A.d
http://dstress.kuehne.cn/compile/c/const_40_B.d
http://dstress.kuehne.cn/compile/c/const_40_C.d
http://dstress.kuehne.cn/compile/c/const_40_D.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFFUfwbLK5blCcjpWoRAvQeAJ4/cIBgs3KXWqmxmsNNN2lCUhiZIQCgrbm+
nWl9Wy0Jv0MX6ivZkD3TnUk=
=0Vc/
-----END PGP SIGNATURE-----

Comment 2 Rainer Schuetze 2010-03-27 06:11:09 UTC
Semantics is not yet run on the SIZE identifier, so dmd does not know, it is const. The patch invokes semantics if not yet run.

Index: optimize.c
===================================================================
--- optimize.c	(revision 421)
+++ optimize.c	(working copy)
@@ -47,6 +47,8 @@
     Expression *e = NULL;
     if (!v)
 	return e;
+    if (!v->originalType && v->scope) // semantic() not yet run - BUG 461
+	v->semantic (v->scope);
 
     if (v->isConst() || v->isImmutable() || v->storage_class & STCmanifest)
     {
Comment 3 Walter Bright 2010-05-10 14:18:37 UTC
changeset 480
Comment 4 Don 2010-05-18 12:14:42 UTC
Fixed DMD1.061 and DMD2.046.