Thread overview |
---|
January 30, 2015 is it bug? | ||||
---|---|---|---|---|
| ||||
``` import std.container: RedBlackTree; class Manager(TT, alias Cmp = "a<b") { alias Container = RedBlackTree!(TT, Cmp); Container _cont; static init() { auto instance = new typeof(this)(); instance._cont = new Container(); return instance; } } unittest { alias IntManager = Manager!int; auto im = IntManager.init(); } void main() {} ``` run it using rdmd -unittest filename.d it fails in a RedBlackTree unittest with 2.065 and 2.066, is it bug? |
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | The real problem is if I comment my unittest out then it compiles. Why my unittest causes this behaviour? |
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote: > > ``` > import std.container: RedBlackTree; > > class Manager(TT, alias Cmp = "a<b") > { > alias Container = RedBlackTree!(TT, Cmp); > Container _cont; > > static init() > { > auto instance = new typeof(this)(); > instance._cont = new Container(); > return instance; > } > } > > unittest > { > alias IntManager = Manager!int; > auto im = IntManager.init(); > } > > void main() {} > ``` > > run it using > rdmd -unittest filename.d > > it fails in a RedBlackTree unittest with 2.065 and 2.066, is it bug? Reduced: import std.container: RedBlackTree; alias Container = RedBlackTree!(int, "a<b"); Error: [...]/std/container/rbtree.d(850): unittest failure Lines 846-850: static if(less == "a < b") auto vals = [1, 2, 3, 4, 5]; else auto vals = [5, 4, 3, 2, 1]; assert(equal(r, vals)); |
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Friday, 30 January 2015 at 13:11:35 UTC, anonymous wrote:
> Lines 846-850:
>
> static if(less == "a < b")
> auto vals = [1, 2, 3, 4, 5];
> else
> auto vals = [5, 4, 3, 2, 1];
> assert(equal(r, vals));
(Tab + Enter strikes again.)
That test looks wrong. So, Phobos bug I think.
|
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote:
> static init()
> {
> auto instance = new typeof(this)();
> instance._cont = new Container();
> return instance;
> }
have you tried
---
static typeof(this) init()
{
auto instance = new typeof(this)();
instance._cont = new Container();
return instance;
}
---
?
because currently either "void" or a type is missing.
|
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBaz | On 30.01.2015 16:31, BBaz wrote:
> On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote:
>
>> static init()
>> {
>> auto instance = new typeof(this)();
>> instance._cont = new Container();
>> return instance;
>> }
>
> have you tried
>
> ---
> static typeof(this) init()
> {
> auto instance = new typeof(this)();
> instance._cont = new Container();
> return instance;
> }
> ---
>
> ?
>
> because currently either "void" or a type is missing.
>
Type is inferred automatically.
|
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to anonymous | On 30.01.2015 16:14, anonymous wrote:
> On Friday, 30 January 2015 at 13:11:35 UTC, anonymous wrote:
>> Lines 846-850:
>>
>> static if(less == "a < b")
>> auto vals = [1, 2, 3, 4, 5];
>> else
>> auto vals = [5, 4, 3, 2, 1];
>> assert(equal(r, vals));
>
> (Tab + Enter strikes again.)
>
> That test looks wrong. So, Phobos bug I think.
I guess it is bug in this unittest, because it fails if I set predicate less to "a<b" instead of "a < b". Spaces rule in this case.
|
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On Friday, 30 January 2015 at 13:34:57 UTC, drug wrote:
> On 30.01.2015 16:31, BBaz wrote:
>> On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote:
>>
>>> static init()
>>> {
>>> auto instance = new typeof(this)();
>>> instance._cont = new Container();
>>> return instance;
>>> }
>>
>> have you tried
>>
>> ---
>> static typeof(this) init()
>> {
>> auto instance = new typeof(this)();
>> instance._cont = new Container();
>> return instance;
>> }
>> ---
>>
>> ?
>>
>> because currently either "void" or a type is missing.
>>
> Type is inferred automatically.
right, i've forgot that init() is a >>built-in<< property.
But it seemsthat i'm not the only one...
|
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to drug | On 30.01.2015 16:35, drug wrote: > On 30.01.2015 16:14, anonymous wrote: >> On Friday, 30 January 2015 at 13:11:35 UTC, anonymous wrote: >>> Lines 846-850: >>> >>> static if(less == "a < b") >>> auto vals = [1, 2, 3, 4, 5]; >>> else >>> auto vals = [5, 4, 3, 2, 1]; >>> assert(equal(r, vals)); >> >> (Tab + Enter strikes again.) >> >> That test looks wrong. So, Phobos bug I think. > I guess it is bug in this unittest, because it fails if I set predicate > less to "a<b" instead of "a < b". Spaces rule in this case. Filed a bug https://issues.dlang.org/show_bug.cgi?id=14082 |
January 30, 2015 Re: is it bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBaz | On Friday, 30 January 2015 at 13:39:05 UTC, BBaz wrote:
> On Friday, 30 January 2015 at 13:34:57 UTC, drug wrote:
>> On 30.01.2015 16:31, BBaz wrote:
>>> On Friday, 30 January 2015 at 12:32:05 UTC, drug wrote:
>>>
>>>> static init()
>>>> {
>>>> auto instance = new typeof(this)();
>>>> instance._cont = new Container();
>>>> return instance;
>>>> }
>>>
>>> have you tried
>>>
>>> ---
>>> static typeof(this) init()
>>> {
>>> auto instance = new typeof(this)();
>>> instance._cont = new Container();
>>> return instance;
>>> }
>>> ---
>>>
>>> ?
>>>
>>> because currently either "void" or a type is missing.
>>>
>> Type is inferred automatically.
>
> right, i've forgot that init() is a >>built-in<< property.
> But it seemsthat i'm not the only one...
I think that doesn't matter here. Still works fine if you name it something other than "init". I don't know if this works as designed, or if an "auto" return type should be required.
Besides, it's a bad idea to call a member "init", because it steals the name of the default initializer. It doesn't override the default initializer, it just takes its name. The compiler should not accept it, in my opinion.
|
Copyright © 1999-2021 by the D Language Foundation