D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9566 - Regression (2.062): Cannot use struct .init when it contains a static array initialized from a single element.
Summary: Regression (2.062): Cannot use struct .init when it contains a static array i...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2013-02-21 21:26 UTC by Marco Leise
Modified: 2013-02-25 04:56 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 Marco Leise 2013-02-21 21:26:11 UTC
Seeing is believing. Reduced test case:
____________________

import core.stdc.stdlib;

struct SZDDFile
{
	ExpandData* pExpandData = null;

	struct ExpandData
	{
		ubyte[4096] window = 0;
	}

	void open()
	{
		pExpandData = cast(ExpandData*) malloc (ExpandData.sizeof);
		*pExpandData = ExpandData.init;
	}
}
____________________

Error: cannot implicitly convert expression (cast(ubyte)0u) of type ubyte to ubyte[4096LU]
Comment 1 monarchdodra 2013-02-21 22:57:51 UTC
(In reply to comment #0)
> Seeing is believing. Reduced test case:
> ____________________
> 
> import core.stdc.stdlib;
> 
> struct SZDDFile
> {
>     ExpandData* pExpandData = null;
> 
>     struct ExpandData
>     {
>         ubyte[4096] window = 0;
>     }
> 
>     void open()
>     {
>         pExpandData = cast(ExpandData*) malloc (ExpandData.sizeof);
>         *pExpandData = ExpandData.init;
>     }
> }
> ____________________
> 
> Error: cannot implicitly convert expression (cast(ubyte)0u) of type ubyte to
> ubyte[4096LU]

It's not about the surrounding code, but rather, whether or not you use the .init property. Reduced test case:

//----
struct ExpandData
{
    ubyte[4096] window = 0;
}

void main()
{
    ExpandData a;
    auto b = ExpandData.init; //Comment me.
}
//----

Works in 2.061, so is a regression.
Comment 2 monarchdodra 2013-02-21 23:03:44 UTC
(In reply to comment #1)
> It's not about the surrounding code, but rather, whether or not you use the
> .init property.

Right, came from the message boards, where you said "I didn't imagine it would depend on any surrounding code", and didn't notice you had already pinned it in the title.

Please ignore that sentence then.
Comment 4 github-bugzilla 2013-02-24 14:19:30 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/ac3de50bcff047b86ff8fe8778f00e8f4845315c
fix Issue 9566 - Cannot use struct .init when it contains static array initialized from a single element.

https://github.com/D-Programming-Language/dmd/commit/f5eb6d5f9684ff6276cdbc52919b5b877d36d72d
Merge pull request #1688 from 9rnsr/fix9566

[REG 2.062] Issue 9566 - Cannot use struct .init when it contains static array initialized from a single element.
Comment 5 github-bugzilla 2013-02-24 14:21:22 UTC
Commit pushed to 2.062 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/e8521cb9e23119a50a6d97af0f5d9e6e5e16f8bf
Merge pull request #1688 from 9rnsr/fix9566

[REG 2.062] Issue 9566 - Cannot use struct .init when it contains static array initialized from a single element.