D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6551 - struct constructor not recognized when forward referenced
Summary: struct constructor not recognized when forward referenced
Status: RESOLVED DUPLICATE of issue 9441
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks: 340
  Show dependency treegraph
 
Reported: 2011-08-24 16:51 UTC by Trass3r
Modified: 2013-11-22 01:37 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 Trass3r 2011-08-24 16:51:05 UTC
So there's a struct with a ubyte. To shut up dmd about implicit conversions I added a constructor but it isn't recognized.

// this failes
immutable int dummy = init();
int init()
{
	uint x;
6:	auto p = F(x);
	return 0;
}

struct F
{
	ubyte th;
	this(uint x)
	{ th = cast(ubyte) x; }
}

// while it works in this case
void main()
{
	uint x;
	auto p = F(x);
}

$ dmd -c posecells.d 
DMD v2.055 DEBUG
posecells.d(6): Error: cannot implicitly convert expression (x) of type uint to ubyte
posecells.d(2): Error: cannot evaluate init() at compile time

Weird thing is, if you remove 'int' in front of 'dummy' it magically works.
Comment 1 Don 2011-09-01 04:30:48 UTC
This isn't a CTFE bug. Reduced test case:

uint NINE = 9;
typeof(F(NINE)) fails;

struct F
{
    ubyte th;
    this(uint x)
    { th = cast(ubyte) x; }
}

This is a forward reference issue. It compiles if you move the declaration of 'fails' past the declaration of F.
Comment 2 Kenji Hara 2013-11-22 01:37:24 UTC

*** This issue has been marked as a duplicate of issue 9441 ***