Issue 6905 - ref acts as auto ref when return type is missing #1401

Merged
merged 1 commit into from Jan 9, 2013

Conversation

Projects
None yet
2 participants

@9rnsr 9rnsr referenced this pull request in dlang/phobos Dec 24, 2012

Merged

Additional fix for issue 6905 #1028

@ghost

ghost commented Dec 24, 2012

I think I'm going to write a pull request to update the documentation, because this isn't described anywhere:

ref bar1() { static int n; return n; }

IOW, ref can act as type inference just like auto can, except ref forces lvalue returns, auto forces rvalue returns, and auto ref is automatic.

However I'm not sure if this is deliberately designed this way or just another case of attributes acting as if they're auto. For example Issue 3573 (and there are other duplicate reports like this where a keyword acts as auto).

Member

9rnsr commented Dec 24, 2012

From a long time ago, I have thought it is a feature. All function attributes with no explicit return type introduces return type inference. Certainly, in the early on the D2, Walter might had not intended about that. But I could not find any problems there in thinking of my three years. So, I can say there is no problem.

@ghost

ghost commented Dec 24, 2012

From a long time ago, I have thought it is a feature. All function attributes with no explicit return type introduces return type inference.

I think it only makes sense for ref. If you use const:

const foo() { ... }

If foo is a method, does const apply to the method or the return type? And is foo a void method or a method that returns?

nothrow and pure are also attributes which are confusing because you can't tell if the function returns or not. I think we need to talk with @WalterBright and @andralex and decide exactly which attributes can be used for type inference. I think auto, auto ref, and ref should be the only ones.

Edit: I think const ref and maybe const auto also work, but I'm unsure. But I think they should be allowed if they work. We have so many of these..

Member

9rnsr commented Dec 24, 2012

If foo is a method, does const apply to the method or the return type? And is foo a void method or a method that returns?

const apply to the method. I know there is a kind of confusing, but it is a different issue.

nothrow and pure are also attributes which are confusing because you can't tell if the function returns or not.

All return type inference implies "you can't tell if the function returns or not". It is the purpose.

Or, you are talking about ref + void return? If so, I can agree it is bit weird.

@9rnsr 9rnsr closed this Dec 25, 2012

@9rnsr 9rnsr reopened this Dec 25, 2012

WalterBright added a commit that referenced this pull request Jan 9, 2013

Merge pull request #1401 from 9rnsr/fix6905
Issue 6905 - ref acts as auto ref when return type is missing

@WalterBright WalterBright merged commit f193abd into dlang:master Jan 9, 2013

1 check was pending

default Pending: 10
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment