Re: Why does this compile (method in class without return type)

2017-05-08 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-05-03 14:50, Adam D. Ruppe wrote: No accident there, the spec says any storage class will do: http://dlang.org/spec/function.html#auto-functions "An auto function is declared without a return type. If it does not already have a storage class, use the auto storage class. " I see. --

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 07:37:31 UTC, Jacob Carlborg wrote: It might be by accident but I think the compiler is inferring the return type. Just as "auto" is not necessary to infer the type of a variable if there's another attribute: No accident there, the spec says any storage class will

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 09:21:47 UTC, nkm1 wrote: On Wednesday, 3 May 2017 at 07:34:03 UTC, Daniel Kozák wrote: print in A is template: What :) How does it interact with 'final'? If it were a template (and it's not), then final would not be applicable, because templated functions

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 07:34:03 UTC, Daniel Kozák wrote: V Wed, 03 May 2017 06:54:15 + nkm1 via Digitalmars-d-learn napsáno: Consider: import std.stdio; class A { final print() { writeln(this); } // no return type } class B : A { final

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 03 May 2017 09:21:47 + nkm1 via Digitalmars-d-learn napsáno: > On Wednesday, 3 May 2017 at 07:34:03 UTC, Daniel Kozák wrote: > > > > print in A is template: > > > > What :) > How does it interact with 'final'? hmm obviously it is problem only

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 03 May 2017 09:21:47 + nkm1 via Digitalmars-d-learn napsáno: > On Wednesday, 3 May 2017 at 07:34:03 UTC, Daniel Kozák wrote: > > > > print in A is template: > > > > What :) > How does it interact with 'final'? final is not important here

Re: Why does this compile (method in class without return type)

2017-05-03 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 07:34:03 UTC, Daniel Kozák wrote: print in A is template: What :) How does it interact with 'final'?

Re: Why does this compile (method in class without return type)

2017-05-03 Thread nkm1 via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 06:54:15 UTC, nkm1 wrote: final method type inference stuff Jacob and Jonathan - thank you, this is clear to me now. Hopefully it will get fixed at some point.

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 08:10:04 UTC, Jonathan M Davis wrote: So, I'd say that there's definitely a bug here. https://issues.dlang.org/show_bug.cgi?id=17366

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, 3 May 2017 at 07:37:31 UTC, Jacob Carlborg wrote: It might be by accident but I think the compiler is inferring the return type. Just as "auto" is not necessary to infer the type of a variable if there's another attribute: auto a = 3; const auto b = 4; // here "auto" is

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-05-03 08:54, nkm1 wrote: Consider: import std.stdio; class A { final print() { writeln(this); } // no return type } class B : A { final void print() { writeln(this); } } void main() { auto b = new B; b.print(); A a1 = b; a1.print(); A a2 = new A;

Re: Why does this compile (method in class without return type)

2017-05-03 Thread Daniel Kozák via Digitalmars-d-learn
V Wed, 03 May 2017 06:54:15 + nkm1 via Digitalmars-d-learn napsáno: > Consider: > > import std.stdio; > > class A > { > final print() { writeln(this); } // no return type > } > > class B : A > { > final void print() { writeln(this); } > } > >

Why does this compile (method in class without return type)

2017-05-03 Thread nkm1 via Digitalmars-d-learn
Consider: import std.stdio; class A { final print() { writeln(this); } // no return type } class B : A { final void print() { writeln(this); } } void main() { auto b = new B; b.print(); A a1 = b; a1.print(); A a2 = new A; a2.print(); } That compiles: $ dmd