www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - function and variable

reply "Fyodor Ustinov" <ufm ufm.su> writes:
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.
Feb 09 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
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
Feb 09 2015
next sibling parent "Fyodor Ustinov" <ufm ufm.su> writes:
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();
Feb 09 2015
prev sibling parent reply "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
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?
Feb 09 2015
parent reply "Fyodor Ustinov" <ufm ufm.su> writes:
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.
Feb 09 2015
parent "Vlad Levenfeld" <vlevenfeld gmail.com> writes:
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.
Feb 09 2015