1160 – enums can not be forward referenced

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1160 - enums can not be forward referenced
Summary: enums can not be forward referenced
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks: 340 390
Show dependency tree / graph
Reported: 2007年04月18日 03:43 UTC by Marcin Kuszczak
Modified: 2014年02月16日 15:22 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Marcin Kuszczak 2007年04月18日 03:43:20 UTC
//related to: http://dstress.kuehne.cn/run/forward_reference_[07-11].d
//doesn't work in almost all contexts
interface Test {
 Policy fn();
}
//same for classes, unions and structs
enum Policy {Default, Cached, Direct}
void main() {
}
Comment 1 Tomas Lindquist Olsen 2008年01月10日 16:52:39 UTC
the simplest test case is something like this:
X x;
enum X { Y };
Fails to compile with 'enum is forward referenced' error.
This issue came up on IRC and I decided to take a look what was going on.
The issue is that the basetype cannot be resolved.
A working workaround is:
X x;
enum X : int { Y };
This patch (against LLVMDC, might not match 100%) ...
Index: dmd/declaration.c
===================================================================
--- dmd/declaration.c (revision 135)
+++ dmd/declaration.c (working copy)
@@ -642,6 +642,7 @@
 Dsymbol *parent = toParent();
 FuncDeclaration *fd = parent->isFuncDeclaration();
+ type->semantic(loc,sc);
 Type *tb = type->toBasetype();
 if (tb->ty == Tvoid && !(storage_class & STClazy))
 { error("voids have no value");
... also fixes the problem. I have no idea what other problems it might introduce though... Also I doubt it will fix all the variations of this issue. I haven't looked enough at the semantics code in DMD to fix this properly.
However, this seems like something that shouldn't be *that* hard to fix... Why not put in the works for Type::toBaseType to be able to run semantics?
Please enlighten me (us) as to why this is implemented as it is right now!
Comment 2 Walter Bright 2008年01月15日 04:07:43 UTC
The patch doesn't work generally because the context (sc) for the type may be very different from the context for the enum.
Comment 3 Walter Bright 2009年12月29日 03:19:59 UTC
Changeset 318
Comment 4 Walter Bright 2009年12月31日 11:10:28 UTC
Fixed dmd 1.054 and 2.038


AltStyle によって変換されたページ (->オリジナル) /