[Issue 3572] declaring pure function with void return type should be compile time error

2020-03-25 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3572

--- Comment #10 from Michal Minich  ---
Agreed. even 

pure void nothrow never() { assert(false); } 

can throw Error, which is observable effect.

--


[Issue 3572] declaring pure function with void return type should be compile time error

2020-03-24 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3572

Dennis  changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 CC||dkor...@live.nl
 Resolution|--- |INVALID

--- Comment #9 from Dennis  ---
(In reply to yebblies from comment #8)
> eg.
> pure void foo(string x)
> By definition calling foo does no observable work.

False.

```
pure void foo(string x) {
throw new Exception(x);
}
```

Here's a nothrow one:
```
pure nothrow void assertPositive(int x) {
assert(x > 0);
}
```

> While this might be WONTFIX or LATER like issue 3882, it is not invalid.

Until a case can be identified where there is actually "no observable work"
guaranteed, this is invalid.

(And even then, it's debatable whether "no observable work" is enough grounds
to make something not compile. `int x = 0; x += 0;` does nothing, but it does
and should compile.)

--


[Issue 3572] declaring pure function with void return type should be compile time error

2013-03-06 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 CC||yebbl...@gmail.com
Version|2.036   |D2
 Resolution|INVALID |
   Severity|normal  |enhancement


--- Comment #8 from yebblies yebbl...@gmail.com 2013-03-06 21:46:46 EST ---
(In reply to comment #7)
 In current, we can declare a pure function which has weak purity.
 
 pure void foo(int* p, out string s, ref int[] arr);
 
 All results are returned through its parameters.
 So, returning void itself has no problem in pure functions.

This would still be meaningful for strongly-pure or const-pure functions.

eg.
pure void foo(string x)
By definition calling foo does no observable work.

While this might be WONTFIX or LATER like issue 3882, it is not invalid.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2013-02-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Andrej Mitrovic andrej.mitrov...@gmail.com changed:

   What|Removed |Added

 CC||andrej.mitrov...@gmail.com


--- Comment #6 from Andrej Mitrovic andrej.mitrov...@gmail.com 2013-02-03 
15:53:14 PST ---
(In reply to comment #3)
 (In reply to comment #2)
  ?  Why would you allow out parameters in a pure function?  This seems
  reasonable for simple value types (ints, floats, etc.), but when you start
  passing objects in, you start allowing the modification of whole object
  subgraphs from pure functions.  This makes no sense.
 
 Why doesn't it make sense? Aren't you thinking of inout parameters? A pure
 function  void foo(out A a); ought to be exactly the same as A foo(); together
 with an assignment. I'm not seeing anything impure in that.
 BTW, it works fine in CTFE. (CTFE isn't quite the same concept as pure, but
 it's close).

Should we close this report then?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2013-02-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Kenji Hara k.hara...@gmail.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||INVALID


--- Comment #7 from Kenji Hara k.hara...@gmail.com 2013-02-03 18:50:45 PST ---
In current, we can declare a pure function which has weak purity.

pure void foo(int* p, out string s, ref int[] arr);

All results are returned through its parameters.
So, returning void itself has no problem in pure functions.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2012-01-05 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Trass3r mrmoc...@gmx.de changed:

   What|Removed |Added

   Keywords||accepts-invalid, diagnostic
 CC||mrmoc...@gmx.de
   Platform|x86 |All
 OS/Version|Windows |All
   Severity|enhancement |normal


--- Comment #5 from Trass3r mrmoc...@gmx.de 2012-01-05 14:19:40 PST ---
Also you shouldn't be able to throw away the result of a pure function.
http://d.puremagic.com/issues/show_bug.cgi?id=7235

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2010-02-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572



--- Comment #4 from David Simcha dsim...@yahoo.com 2010-02-17 18:38:36 PST ---
(In reply to comment #3)
 Why doesn't it make sense? Aren't you thinking of inout parameters? A pure
 function  void foo(out A a); ought to be exactly the same as A foo(); together
 with an assignment. I'm not seeing anything impure in that.
 BTW, it works fine in CTFE. (CTFE isn't quite the same concept as pure, but
 it's close).

You're right, I did get confused between out and ref.  Allowing out parameters
in pure functions makes sense.  I tend to forget how out parameters work
because I almost never use them.  I almost always just return a tuple or a
struct.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2009-12-04 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

 CC||clugd...@yahoo.com.au


--- Comment #1 from Don clugd...@yahoo.com.au 2009-12-04 12:01:56 PST ---
(In reply to comment #0)
 In D specification is written: Pure functions are functions that produce the
 same result for the same arguments. To that end, a pure function has 
 parameters
 that are all immutable or are implicitly convertible to immutable
 
 void function cannot produce any result, thus they are meaningless as pure
 functions. Also when all parameters are implicitly immutable, there is no
 possibility to modify out parameters. So the only way for function to 
 produce
 result, is by returning it (and void has no value).

I think the restriction on 'out' parameters will be removed. I don't think
there's any reason for it.
A void pure function that doesn't have any 'out' parameters does seem to be
pretty useless (you can use it as a metaprogramming test that anything inside
it is pure, but that's about all I can think of).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3572] declaring pure function with void return type should be compile time error

2009-12-04 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3572



--- Comment #3 from Don clugd...@yahoo.com.au 2009-12-04 18:28:11 PST ---
(In reply to comment #2)
 ?  Why would you allow out parameters in a pure function?  This seems
 reasonable for simple value types (ints, floats, etc.), but when you start
 passing objects in, you start allowing the modification of whole object
 subgraphs from pure functions.  This makes no sense.

Why doesn't it make sense? Aren't you thinking of inout parameters? A pure
function  void foo(out A a); ought to be exactly the same as A foo(); together
with an assignment. I'm not seeing anything impure in that.
BTW, it works fine in CTFE. (CTFE isn't quite the same concept as pure, but
it's close).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---