Jump to page: 1 2 3
Thread overview
[Issue 12931] Make const, immutable, inout, and shared illegal as function attributes on the left-hand side of a function
[Issue 12931] Make const, immutable, and inout illegal as funtion attributes on the left-hand side of a function
Jun 18, 2014
Jonathan M Davis
Jun 24, 2014
Kenji Hara
Jun 24, 2014
Jonathan M Davis
[Issue 12931] Make const, immutable, inout, and shared illegal as funtion attributes on the left-hand side of a function
Jun 24, 2014
Jonathan M Davis
Jun 24, 2014
Jonathan M Davis
Jun 24, 2014
Kenji Hara
Oct 04, 2014
Kenji Hara
Oct 04, 2014
deadalnix
Oct 04, 2014
Kenji Hara
Oct 04, 2014
Ketmar Dark
Oct 19, 2014
Martin Nowak
Aug 11, 2019
Mathias LANG
Feb 03, 2020
Dlang Bot
Feb 03, 2020
Dlang Bot
Feb 03, 2020
Dlang Bot
Feb 17, 2020
Mathias LANG
June 16, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc

--- Comment #1 from bearophile_hugs@eml.cc ---
I think there is already a closed issue on this topic. So perhaps it's better to reopen it instead of opening a dupe.


(In reply to Jonathan M Davis from comment #0)

> I know that Walter doesn't agree with this (or at least hasn't in the past),

Walter changes his mind when the evidence and need are strong.

--
June 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--
June 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
June 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|safe                        |

--
June 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

Jonathan Crapuchettes <jcrapuchettes@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jcrapuchettes@gmail.com

--- Comment #2 from Jonathan Crapuchettes <jcrapuchettes@gmail.com> ---
I'm in agreement. It would be really nice to have this disallowed for the sake of new people coming to the language. It can be very confusing.

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> ---
(In reply to Jonathan M Davis from comment #0)
> Can we _please_, _please_ make it illegal to put any function attribute which could also modify the return type on the left-hand side of the function?

I think it would be nice improvement.

> It would be nice to make it so that
> 
> const Bar foo() {...}
> 
> were then the same as
> 
> const(Bar) foo() {...}

There was a discussion in issue 10150 about it.

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #4 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to Jonathan M Davis from comment #0)

> The reason that's usually given as to why const is legal on the left-hand side is because all function attributes can go on either side of the function, and it would be inconsistent to disallow const, immutable, or inout on the left. But that's not even true! As issue# 12930 shows, static, private, public, package, and protected are all illegal on the left.

You mean "illegal on the *right*"

Some questions:

these are currently also legal and equivalent to your example:

const: Bar foo() {...}
const{ Bar foo() {...} }

Those OK or not? I'd say yes, because the only really confusing one is where the const seems to apply to Bar. In those cases, const looks more like a class-level attribute, and don't appear to apply to the return type.

Come to think of it, this is also not ambiguous:

const void foo() {...}

But I think this should also be disallowed for consistency

Also, shared is in this category, as it is a type constructor.

9 votes in 7 days, must be some sort of record :) I'll add mine shortly. I would guess that there would be zero

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

--- Comment #5 from Steven Schveighoffer <schveiguy@yahoo.com> ---
(In reply to Steven Schveighoffer from comment #4)

> 9 votes in 7 days, must be some sort of record :)

Hah, I didn't realize we can now vote more than once for an issue. Really Jonathan, 9 votes?

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

--- Comment #6 from Jonathan M Davis <jmdavisProg@gmx.com> ---
> You mean "illegal on the *right*"

Yeah, sorry.

> these are currently also legal and equivalent to your example:

> const: Bar foo() {...}
> const{ Bar foo() {...} }

> Those OK or not?

I'd say yes. What needs to be illegal are ambiguous cases. There's no way that const: or const{} could refer to the return type.

> Come to think of it, this is also not ambiguous:

> const void foo() {...}

> But I think this should also be disallowed for consistency

Agreed. Even if it's clear to the compiler, it's just bizarre to the programmer. Also, if we can ever get to the point that const without parens on left applies to the return type rather than the function, then allowing const void would definitely be bad.

> Also, shared is in this category, as it is a type constructor.

Yeah. Any attribute which could affect the return type should be illegal no the left.

> Hah, I didn't realize we can now vote more than once for an issue. Really Jonathan, 9 votes?

LOL. Well, that's how many votes I had, and I was really ticked about this when I created it, so when I figured out that it would let me put multiple votes on it, I did. The fact that public, private, static, etc. can't go on the right completely goes against the entire argument for why const is allowed on the left, and as soon as I figured that I out, I was pretty mad that we'd ever agreed to let const be on the left. The whole consistency argument is bogus with regards to the current implementation, and I've never thought that the consistency was worth it here anyway. We either need to actually make them all consistent and let them all go on the right or disallow the ones on the left that are ambiguous. I vote strongly for the latter, as it's less bug-prone.

--
June 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12931

Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Make const, immutable, and  |Make const, immutable,
                   |inout illegal as funtion    |inout, and shared illegal
                   |attributes on the left-hand |as funtion attributes on
                   |side of a function          |the left-hand side of a
                   |                            |function

--
« First   ‹ Prev
1 2 3