D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1030 - Delegate literal as initializer is confused with struct initializer
Summary: Delegate literal as initializer is confused with struct initializer
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:
 
Reported: 2007-03-07 13:20 UTC by FeepingCreature
Modified: 2014-04-18 09:12 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2007-03-07 13:20:34 UTC
The following one-liner causes an ICE in line 0. Verified on GDC .21, .23 and DMD 1.007:

void main() { void delegate() test={ struct test2 {;} }; }

Greetings, downs
Comment 2 Walter Bright 2007-03-19 17:41:50 UTC
Fixed DMD 1.009
Comment 3 david 2007-11-07 21:59:52 UTC
Seems 1.022 doesn't compile this, and 1.009 compiles this?
Comment 4 FeepingCreature 2007-11-08 04:40:11 UTC
(In reply to comment #3)
> Seems 1.022 doesn't compile this, and 1.009 compiles this?
> 

Strange. Builds fine on my gdc .24/1.022 under linux/32-bit.
Comment 5 david 2007-11-08 19:40:12 UTC
it's http://dstress.kuehne.cn/run/s/struct_29_B.d which can't pass the parse stage. 

seems dmd need a semicolon in the struct in the delegate. 
Comment 6 Don 2009-04-18 17:33:01 UTC
This is really a totally different bug to the original one, and much less severe. No longer an ICE -- it's a pretty tiny issue.

void main() {
	void delegate() test = {
		struct test2{}
	}
}
---
fog.d(4): expression expected, not 'struct'
fog.d(4): comma expected separating field initializers
fog.d(5): semicolon expected, not '}'
----
Comment 7 Stewart Gordon 2009-04-19 07:29:13 UTC
> fog.d(5): semicolon expected, not '}'

This last message is the one that's correct.  A declaration of a variable (which is what test is) always requires a closing semicolon.

What's actually happening is that it's trying to parse 
{ struct test2{} }
as a struct initializer.  Nothing to do with the struct that's actually declared inside.  See for yourself:

----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz1030a.d
void main() {
        void delegate() test = {
                struct test2{}
        };
}

C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bz1030a.d
bz1030a.d(4): expression expected, not 'struct'
bz1030a.d(4): comma expected separating field initializers

C:\Users\Stewart\Documents\Programming\D\Tests\bugs>type bz1030b.d
void main() {
        void delegate() test;
        test = {
                struct test2{}
        };
}

C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd bz1030b.d

C:\Users\Stewart\Documents\Programming\D\Tests\bugs>
----------

Since AIUI there's no overlap between what's parseable as a struct init and what's parseable as a delegate literal, there should be little or no problem getting it to work.
Comment 8 Don 2009-09-15 06:36:54 UTC
This remaining bug is not a regression. It behaved exactly the same way in DMD0.175.
Another of these annoying cases where we have two unrelated bugs in the same report. It should not have been reopened.
Comment 9 Don 2010-01-18 06:38:18 UTC
The original bug was fixed in 1.009. The bug reported in the comments is the same as bug 1371; I'm therefore closing this one.