Re: UFCS overrides alias this

2015-04-12 Thread anonymous via Digitalmars-d

On Sunday, 12 April 2015 at 20:19:02 UTC, Freddy wrote:


test.d
struct A{
string b;
alias b this;
}

struct MyRange{

}
char front(MyRange);
void popFront(ref MyRange);
bool empty(MyRange);

void test(A a){
a.empty;
}

$ dmd -o- test
test.d(14): Error: function test.empty (MyRange) is not 
callable using argument types (A)


Is this intended behavior?


string's empty is actually a function in std.array or std.range 
or something, called via UFCS. You don't import std's empty, so 
the call can't match even when the alias this is tried.


Add the following, which brings std's empty into the overload 
set, and it works:


static import std.range;
alias empty = std.range.empty;


Re: UFCS overrides alias this

2015-04-12 Thread anonymous via Digitalmars-d

On Sunday, 12 April 2015 at 20:48:57 UTC, Freddy wrote:

test.d
static import std.range;
alias empty=std.range.empty;
struct A{
string b;
alias b this;
}

struct MyRange{

}
char front(MyRange);
void popFront(ref MyRange);
bool empty(MyRange);

void test(A a){
a.empty;
}

$ dmd -o- test
test.d(16): Error: overload alias 'empty' is not a variable

No idea what dmd is doing.


Looks like order matters.

This works:

bool empty(MyRange);
alias empty = std.range.empty;

This doesn't:

alias empty = std.range.empty;
bool empty(MyRange);

I don't know if there's a reason for that or if dmd is just being 
silly.


UFCS overrides alias this

2015-04-12 Thread Freddy via Digitalmars-d


test.d
struct A{
string b;
alias b this;
}

struct MyRange{

}
char front(MyRange);
void popFront(ref MyRange);
bool empty(MyRange);

void test(A a){
a.empty;
}

$ dmd -o- test
test.d(14): Error: function test.empty (MyRange) is not callable 
using argument types (A)


Is this intended behavior?


Re: UFCS overrides alias this

2015-04-12 Thread Freddy via Digitalmars-d

On Sunday, 12 April 2015 at 20:35:06 UTC, anonymous wrote:
string's empty is actually a function in std.array or std.range 
or something, called via UFCS. You don't import std's empty, so 
the call can't match even when the alias this is tried.


Add the following, which brings std's empty into the overload 
set, and it works:


static import std.range;
alias empty = std.range.empty;

test.d
static import std.range;
alias empty=std.range.empty;
struct A{
string b;
alias b this;
}

struct MyRange{

}
char front(MyRange);
void popFront(ref MyRange);
bool empty(MyRange);

void test(A a){
a.empty;
}

$ dmd -o- test
test.d(16): Error: overload alias 'empty' is not a variable

No idea what dmd is doing.

However it works with

private auto empty(string s){
static import std.range;
return std.range.empty(s);
}