Re: recursive template expansion: Why does this not compile?

2018-03-22 Thread Ontonator via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 23:05:22 UTC, Jonathan M Davis wrote: On Wednesday, March 21, 2018 22:50:32 Ontonator via Digitalmars-d-learn wrote: On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: > On 03/21/2018 01:47 AM, Ontonator wrote: >> The following code does not compile: >>>

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 22:50:32 Ontonator via Digitalmars-d-learn wrote: > On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: > > On 03/21/2018 01:47 AM, Ontonator wrote: > >> The following code does not compile: > >>> [...] > >> > >> It gives the error: > >>> [...] > >> > >> The

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread Ontonator via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 06:39:22 UTC, ag0aep6g wrote: On 03/21/2018 01:47 AM, Ontonator wrote: The following code does not compile: [...] It gives the error: [...] The aliases do not have to be aliases, as long as there is some reference to the class (e.g. method and variable

Re: recursive template expansion: Why does this not compile?

2018-03-21 Thread ag0aep6g via Digitalmars-d-learn
On 03/21/2018 01:47 AM, Ontonator wrote: The following code does not compile: void main() {} class SuperClass {} class TemplatedClass(T : SuperClass) {} class A : SuperClass {     alias T = TemplatedClass!B; } class B : SuperClass {     alias T = TemplatedClass!C; } class C : SuperClass {}

Re: recursive template expansion: Why does this not compile?

2018-03-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 21, 2018 00:47:18 Ontonator via Digitalmars-d-learn wrote: > The following code does not compile: > > void main() {} > > > > class SuperClass {} > > > > class TemplatedClass(T : SuperClass) {} > > > > class A : SuperClass { > > > > alias T = TemplatedClass!B; > > > > } > >

recursive template expansion: Why does this not compile?

2018-03-20 Thread Ontonator via Digitalmars-d-learn
The following code does not compile: void main() {} class SuperClass {} class TemplatedClass(T : SuperClass) {} class A : SuperClass { alias T = TemplatedClass!B; } class B : SuperClass { alias T = TemplatedClass!C; } class C : SuperClass {} It gives the error: test.d(12): Error:

Re: Why does this not compile?

2018-03-07 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 5:27 PM, Timon Gehr wrote: The reasoning "the reference is stored in the type yet not part of the type" does not work for pure functions, as then you cannot offer an alternative explanation in terms of an external data store. Yeah, the more I think about it, the more I think the

Re: Why does this not compile?

2018-03-06 Thread Timon Gehr via Digitalmars-d
On 06.03.2018 17:19, Steven Schveighoffer wrote: unittest { int n = 0; struct S { int fun() const { return n; } } immutable S s; assert(s.fun == 0); n++; assert(s.fun == 1); // Not so immutable now, are you? } That's not a demonstration of breaking

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 10:00 AM, Simen Kjærås wrote: On Tuesday, 6 March 2018 at 13:56:30 UTC, Steven Schveighoffer wrote: On 3/6/18 8:42 AM, Simen Kjærås wrote: unittest { int i = 0; struct S { int n; void fun() const { i++; } } const S s;

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 9:42 AM, Shachar Shemesh wrote: I fail to see any reasoning[1] that disallows the former but allows the later. 1 - That is obviously not true. I see the reasoning all too well. Static vars are like globals, and you're not getting to them via the struct's instance. I would argue

Re: Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
On 06/03/18 17:00, Simen Kjærås wrote: Interestingly, replacing 'const' with 'immutable' on fun gives a compilation error: "immutable function 'foo.__unittest_foo_1_0.S.fun' cannot access mutable data 'n'". This just means it is completely and totally broken. Changing the "const" to

Re: Why does this not compile?

2018-03-06 Thread Simen Kjærås via Digitalmars-d
On Tuesday, 6 March 2018 at 13:56:30 UTC, Steven Schveighoffer wrote: On 3/6/18 8:42 AM, Simen Kjærås wrote: unittest {     int i = 0;     struct S {     int n;     void fun() const {     i++;     }     }     const S s;     assert(i == 0);     s.fun();    

Re: Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
Filed issue 18563 Shachar

Re: Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
On 06/03/18 16:06, Steven Schveighoffer wrote: On 3/6/18 8:56 AM, Steven Schveighoffer wrote: So a bug report is in order. It should be decided one way or another -- either the context pointer is part of the struct type or it isn't. There is a third possibility: It's part of the type AND

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 8:56 AM, Steven Schveighoffer wrote: On 3/6/18 8:42 AM, Simen Kjærås wrote: It's a bug. As pointed out elsewhere in this thread, it compiles correctly when there's no destructor. Essentially, this bug is caused by the context pointer being typed as void*, and becoming (of course)

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 8:42 AM, Simen Kjærås wrote: It's a bug. As pointed out elsewhere in this thread, it compiles correctly when there's no destructor. Essentially, this bug is caused by the context pointer being typed as void*, and becoming (of course) const(void*) for a const(S). If it'd been

Re: Why does this not compile?

2018-03-06 Thread Simen Kjærås via Digitalmars-d
On Tuesday, 6 March 2018 at 12:00:43 UTC, Steven Schveighoffer wrote: On 3/6/18 6:21 AM, Simen Kjærås wrote: On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() {     struct S {     uint value;     ~this() {     }     }     const S a = S(12);     S b = a;

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 7:44 AM, Shachar Shemesh wrote: On 06/03/18 14:00, Steven Schveighoffer wrote: On 3/6/18 6:21 AM, Simen Kjærås wrote: On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() {     struct S {     uint value;     ~this() {     }     }     const S a =

Re: Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
On 06/03/18 14:00, Steven Schveighoffer wrote: On 3/6/18 6:21 AM, Simen Kjærås wrote: On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() {     struct S {     uint value;     ~this() {     }     }     const S a = S(12);     S b = a; } test.d(10): Error:

Re: Why does this not compile?

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d
On 3/6/18 6:21 AM, Simen Kjærås wrote: On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() {     struct S {     uint value;     ~this() {     }     }     const S a = S(12);     S b = a; } test.d(10): Error: cannot implicitly convert expression a of type

Re: Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
On 06/03/18 12:16, Diego wrote: You cannot assign a const element (`a`) to a non-const element (`b`) in `S b = a` expression. Sure you can. During assignment you are making a copy. Why do you care whether the original is const? Shachar

Re: Why does this not compile?

2018-03-06 Thread Simen Kjærås via Digitalmars-d
On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() { struct S { uint value; ~this() { } } const S a = S(12); S b = a; } test.d(10): Error: cannot implicitly convert expression a of type const(S) to S Looks like a bug to me -

Re: Why does this not compile?

2018-03-06 Thread Diego via Digitalmars-d
On Tuesday, 6 March 2018 at 10:03:54 UTC, Shachar Shemesh wrote: void main() { struct S { uint value; ~this() { } } const S a = S(12); S b = a; } You cannot assign a const element (`a`) to a non-const element (`b`) in `S b = a` expression. To make de

Why does this not compile?

2018-03-06 Thread Shachar Shemesh via Digitalmars-d
void main() { struct S { uint value; ~this() { } } const S a = S(12); S b = a; } test.d(10): Error: cannot implicitly convert expression a of type const(S) to S Doing *any* of the following makes the code compile: * Making the struct "static" * Making

Why does it not compile?

2011-03-24 Thread Morlan
import std.stdio; void Foo(T:T*)(T arg) if(!is(T==int)) { writeln(arg of Foo:, arg, typeid(T)); } void Foo(T:T*)(T arg) if(is(T==int)) { writeln(int Foo!); } void main() { Foo!(long*)(54); }

Re: Why does it not compile?

2011-03-24 Thread bearophile
Morlan: ... This compiles, 54 is an int: import std.stdio; void Foo(T: T*)(T arg) if(!is(T == int)) { writeln(Arg of Foo: , arg, , typeid(T)); } void Foo(T: T*)(T arg) if(is(T == int)) { writeln(int Foo!); } void main() { Foo!(long*)(54L); } Generally for questions like this,

Re: Why does it not compile?

2011-03-24 Thread Morlan
I did not ask what to do to compile it. I knew that 54L would do. The problem is that in the example I explicitely specify the template parameter as long* so there is no reason for the compiler to try and guess T from the type of the function argument. There is something wrong here.

Re: Why does it not compile?

2011-03-24 Thread Daniel Gibson
Am 24.03.2011 11:49, schrieb Morlan: I did not ask what to do to compile it. I knew that 54L would do. The problem is that in the example I explicitely specify the template parameter as long* so there is no reason for the compiler to try and guess T from the type of the function argument. There

Re: Why does it not compile?

2011-03-24 Thread Morlan
The program below compiles. Clearly the if constraints in my original example are causing trouble. It seems like a bug to me. import std.stdio; void Foo(T:T*)(T arg) { writeln(arg of Foo:, arg, typeid(T)); } void main() { Foo!(long*)(54); }

Re: Why does it not compile?

2011-03-24 Thread bearophile
Morlan: I did not ask what to do to compile it. I knew that 54L would do. The problem is that in the example I explicitely specify the template parameter as long* so there is no reason for the compiler to try and guess T from the type of the function argument. There is something wrong