Thread overview
function and variable
Feb 10, 2015
Fyodor Ustinov
Feb 10, 2015
Rikki Cattermole
Feb 10, 2015
Fyodor Ustinov
Feb 10, 2015
Vlad Levenfeld
Feb 10, 2015
Fyodor Ustinov
Feb 10, 2015
Vlad Levenfeld
February 10, 2015
Hi!

I think this code should not be compiled without any warning:

import std.stdio;

void f(int a) {
    writeln("it's a function! : ", a);
}

void main() {
    auto f = function (int a) {writeln("It's a variable! : ", a);};
    5.f();
    f(5);
}

Output:

it's a function! : 5
It's a variable! : 5

WBR,
    Fyodor.
February 10, 2015
On 10/02/2015 4:28 p.m., Fyodor Ustinov wrote:
> Hi!
>
> I think this code should not be compiled without any warning:
>
> import std.stdio;
>
> void f(int a) {
>      writeln("it's a function! : ", a);
> }
>
> void main() {
>      auto f = function (int a) {writeln("It's a variable! : ", a);};
>      5.f();
>      f(5);
> }
>
> Output:
>
> it's a function! : 5
> It's a variable! : 5
>
> WBR,
>      Fyodor.

That's a bug. It should be using the function pointer.

UFCS call should abide by the same scoping rules as anything else.
https://issues.dlang.org/show_bug.cgi?id=14161
February 10, 2015
On Tuesday, 10 February 2015 at 03:59:22 UTC, Rikki Cattermole wrote:
> That's a bug. It should be using the function pointer.
>
> UFCS call should abide by the same scoping rules as anything else.
> https://issues.dlang.org/show_bug.cgi?id=14161

Moreover. If the function is not defined (only pointer), I get this error:

aa.d(5): Error: no property 'f' for type 'int'

when try use 5.f();
February 10, 2015
On Tuesday, 10 February 2015 at 03:59:22 UTC, Rikki Cattermole wrote:
> That's a bug. It should be using the function pointer.
>
> UFCS call should abide by the same scoping rules as anything else.
> https://issues.dlang.org/show_bug.cgi?id=14161

I thought that's how UFCS was explicitly designed? Global symbols only, yes?
February 10, 2015
On Tuesday, 10 February 2015 at 04:11:43 UTC, Vlad Levenfeld wrote:
> On Tuesday, 10 February 2015 at 03:59:22 UTC, Rikki Cattermole wrote:
>> That's a bug. It should be using the function pointer.
>>
>> UFCS call should abide by the same scoping rules as anything else.
>> https://issues.dlang.org/show_bug.cgi?id=14161
>
> I thought that's how UFCS was explicitly designed? Global symbols only, yes?

IMHO even if "it is not a bug, it is a feature" - it should not be compiled without notice.

WBR,
    Fyodor.
February 10, 2015
On Tuesday, 10 February 2015 at 04:20:27 UTC, Fyodor Ustinov wrote:
> IMHO even if "it is not a bug, it is a feature" - it should not be compiled without notice.
>
> WBR,
>     Fyodor.

Agreed, should be a warning at least.