4503 – forward reference to aliased template instance

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4503 - forward reference to aliased template instance
Summary: forward reference to aliased template instance
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 major
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks: 340 3679 4267
Show dependency tree / graph
Reported: 2010年07月24日 11:41 UTC by Trass3r
Modified: 2015年06月09日 05:12 UTC (History)
3 users (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 Trass3r 2010年07月24日 11:41:59 UTC
This is an extremely simplified version of my real code (cl4d) where these 3 parts are distributed among several files (and thus heavily depend on the build order).
----
class Collection(T)
{
}
ICollection c;
alias Collection!int ICollection;
fwdref2.d(4): Error: forward reference to 'Collection!(int)'
fwdref2.d(4): Error: ICollection is used as a type
----
Putting ICollection c; at the end makes it compile.
Comment 1 Trass3r 2010年07月24日 12:05:53 UTC
error occurs at mtype.c:5542
if (t->ty == Tinstance && t != this && !t->deco)
{ error(loc, "forward reference to '%s'", t->toChars());
 return;
}
This is also true if ICollection is referenced like this:
void foo(ICollection c)
{
}
Comment 2 Trass3r 2010年07月25日 14:04:50 UTC
A test with
if (t->ty == Tinstance && t != this && !t->deco)
{ //error(loc, "forward reference to '%s'", t->toChars());
 //return;
 t = t->semantic(loc, sc);
}
solved this issue. Don't know if that causes other problems though.
Comment 3 Rainer Schuetze 2010年07月26日 00:32:51 UTC
This patch seems a bit more generic and solved a similar issue for me. It also works for your code:
Index: declaration.c
===================================================================
--- declaration.c	(revision 576)
+++ declaration.c	(working copy)
@@ -594,6 +594,9 @@
 { error("recursive alias declaration");
 aliassym = new TypedefDeclaration(loc, ident, Type::terror, NULL);
 }
+ else if (!aliassym && scope)
+ semantic(scope);
+
 Dsymbol *s = aliassym ? aliassym->toAlias() : this;
 return s;
 }
Comment 4 Trass3r 2010年07月26日 06:05:39 UTC
Great!
Also seems to solve http://d.puremagic.com/issues/show_bug.cgi?id=4267 
Comment 5 Trass3r 2010年07月27日 10:18:02 UTC
And this one: http://d.puremagic.com/issues/show_bug.cgi?id=3679 
Comment 6 Walter Bright 2010年08月08日 21:32:00 UTC
http://www.dsource.org/projects/dmd/changeset/607 
Comment 7 Don 2010年08月29日 12:39:56 UTC
Fixed DMD1.063 and 2.048.


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