Jump to page: 1 2
Thread overview
copying const struct
Oct 14, 2013
Jack Applegame
Oct 14, 2013
Benjamin Thaut
Oct 14, 2013
Jack Applegame
Oct 14, 2013
Dicebot
Oct 14, 2013
Benjamin Thaut
Oct 14, 2013
Maxim Fomin
Oct 14, 2013
Benjamin Thaut
Oct 14, 2013
Maxim Fomin
Oct 14, 2013
Kenji Hara
Oct 14, 2013
Ali Çehreli
Oct 14, 2013
Maxim Fomin
Oct 15, 2013
Jack Applegame
October 14, 2013
Why this doesn't compile?

http://dpaste.dzfl.pl/21ef5b04

class Foo {}

struct Bar1 {
	const(Foo[]) member;	
}

struct Bar2 {
	const Foo member;	
}

void main() {
	const Bar1 bar1;
	const Bar2 bar2;
	Bar1 b1 = bar1; // ok
	Bar2 b2 = bar2; // cannot implicitly convert expression (bar2) of type const(Bar2) to Bar2
}
October 14, 2013
Am 14.10.2013 13:35, schrieb Jack Applegame:
> Why this doesn't compile?
>
> http://dpaste.dzfl.pl/21ef5b04
>
> class Foo {}
>
> struct Bar1 {
>      const(Foo[]) member;
> }
>
> struct Bar2 {
>      const Foo member;
> }
>
> void main() {
>      const Bar1 bar1;
>      const Bar2 bar2;
>      Bar1 b1 = bar1; // ok
>      Bar2 b2 = bar2; // cannot implicitly convert expression (bar2) of
> type const(Bar2) to Bar2
> }

Because in D const is transitive. That means if a reference is const the object it points to is also const. And everything that object points to is const, and so on.

The line "Bar2 b2 = bar2;" would remove const from "member" which does not happen because const is not convertible to mutable implicitly.

Kind Regards
Benjamin Thaut
October 14, 2013
On Monday, 14 October 2013 at 11:38:23 UTC, Benjamin Thaut wrote:
> The line "Bar2 b2 = bar2;" would remove const from "member"
Seems strange, because b2.member is const by declaration.
October 14, 2013
On Monday, 14 October 2013 at 11:45:30 UTC, Jack Applegame wrote:
> On Monday, 14 October 2013 at 11:38:23 UTC, Benjamin Thaut wrote:
>> The line "Bar2 b2 = bar2;" would remove const from "member"
> Seems strange, because b2.member is const by declaration.

Strange indeed and smells like a bug. `auto bar = Bar2(bar2.member)` works so it should be assignable.
October 14, 2013
Am 14.10.2013 13:54, schrieb Dicebot:
> On Monday, 14 October 2013 at 11:45:30 UTC, Jack Applegame wrote:
>> On Monday, 14 October 2013 at 11:38:23 UTC, Benjamin Thaut wrote:
>>> The line "Bar2 b2 = bar2;" would remove const from "member"
>> Seems strange, because b2.member is const by declaration.
>
> Strange indeed and smells like a bug. `auto bar = Bar2(bar2.member)`
> works so it should be assignable.

d.puremagic.com/issues/show_bug.cgi?id=9665
October 14, 2013
On Monday, 14 October 2013 at 11:35:32 UTC, Jack Applegame wrote:
> Why this doesn't compile?
>
> http://dpaste.dzfl.pl/21ef5b04
>
> class Foo {}
>
> struct Bar1 {
> 	const(Foo[]) member;	
> }
>
> struct Bar2 {
> 	const Foo member;	
> }
>
> void main() {
> 	const Bar1 bar1;
> 	const Bar2 bar2;
> 	Bar1 b1 = bar1; // ok
> 	Bar2 b2 = bar2; // cannot implicitly convert expression (bar2) of type const(Bar2) to Bar2
> }

This is compilable using git head.
October 14, 2013
On Monday, 14 October 2013 at 13:56:58 UTC, Benjamin Thaut wrote:
> Am 14.10.2013 13:54, schrieb Dicebot:
>> On Monday, 14 October 2013 at 11:45:30 UTC, Jack Applegame wrote:
>>> On Monday, 14 October 2013 at 11:38:23 UTC, Benjamin Thaut wrote:
>>>> The line "Bar2 b2 = bar2;" would remove const from "member"
>>> Seems strange, because b2.member is const by declaration.
>>
>> Strange indeed and smells like a bug. `auto bar = Bar2(bar2.member)`
>> works so it should be assignable.
>
> d.puremagic.com/issues/show_bug.cgi?id=9665

I don't see how this is related to the topic.
October 14, 2013
Am 14.10.2013 16:19, schrieb Maxim Fomin:
> On Monday, 14 October 2013 at 13:56:58 UTC, Benjamin Thaut wrote:
>> Am 14.10.2013 13:54, schrieb Dicebot:
>>> On Monday, 14 October 2013 at 11:45:30 UTC, Jack Applegame wrote:
>>>> On Monday, 14 October 2013 at 11:38:23 UTC, Benjamin Thaut wrote:
>>>>> The line "Bar2 b2 = bar2;" would remove const from "member"
>>>> Seems strange, because b2.member is const by declaration.
>>>
>>> Strange indeed and smells like a bug. `auto bar = Bar2(bar2.member)`
>>> works so it should be assignable.
>>
>> d.puremagic.com/issues/show_bug.cgi?id=9665
>
> I don't see how this is related to the topic.

I thought maybe its related to this bug.
October 14, 2013
On Monday, 14 October 2013 at 14:18:10 UTC, Maxim Fomin wrote:
> On Monday, 14 October 2013 at 11:35:32 UTC, Jack Applegame wrote:
>> Why this doesn't compile?
>>
>> http://dpaste.dzfl.pl/21ef5b04
>>
>> class Foo {}
>>
>> struct Bar1 {
>> 	const(Foo[]) member;	
>> }
>>
>> struct Bar2 {
>> 	const Foo member;	
>> }
>>
>> void main() {
>> 	const Bar1 bar1;
>> 	const Bar2 bar2;
>> 	Bar1 b1 = bar1; // ok
>> 	Bar2 b2 = bar2; // cannot implicitly convert expression (bar2) of type const(Bar2) to Bar2
>> }
>
> This is compilable using git head.

Recently I found a small compiler bug.
http://d.puremagic.com/issues/show_bug.cgi?id=11187

And, a week ago it is fixed. 2.064 beta1 contains the fix.

Kenji Hara
October 14, 2013
On 10/14/2013 10:33 AM, Kenji Hara wrote:

> On Monday, 14 October 2013 at 14:18:10 UTC, Maxim Fomin wrote:

>> This is compilable using git head.

When I read that line ...

> Kenji Hara

... I was thinking about that person. :)

Thank you Kenji!

Ali

« First   ‹ Prev
1 2