Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old alias syntax accepts "ref" #18724

Open
dlangBugzillaToGithub opened this issue Nov 28, 2013 · 7 comments
Open

Old alias syntax accepts "ref" #18724

dlangBugzillaToGithub opened this issue Nov 28, 2013 · 7 comments

Comments

@dlangBugzillaToGithub
Copy link

Dicebot (@mihails-strasuns) reported this on 2013-11-28T07:29:22Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=11632

CC List

  • Maxim Fomin
  • Bolpat
  • Robert Schadek

Description

When using old alias form, `ref` is both accepted and not making any effect:

-----------
alias ref int RefInt;

void foo(RefInt x)
{
	x = 42;
}

void main()
{
	int x;
	foo(x);
	
	import std.stdio : writeln;
	writeln(x);
}
-----------
0
-----------

`alias RefInt = ref int` is rejected with "Error: basic type expected, not ref" so I assume it should be the same here.
@dlangBugzillaToGithub
Copy link
Author

maxim commented on 2013-11-28T07:46:39Z

More nonsense:

alias ref int ri;
//alias in int ii;
alias int oi;
//alias lazy int li;
//alias out int outi;

alias pure int pi;
alias @safe int si;
//alias trusted int ti;
alias nothrow int nthi;

alias auto int ai;
alias @property int pri;
alias @disable int di;
alias scope int sci;

alias align(16) int ali;

alias abstract int absi;

alias final int fi;
alias override int ovi;
alias inout int inoui;
alias synchronized int syi;

alias static int stati;

It is unclear however, whether this is a part of major accepts-invalid bug (dmd is permissive in allowing to apply attributes to declarations, so here is particular case) or defficiency in old alias syntax parsing.

@dlangBugzillaToGithub
Copy link
Author

public (@mihails-strasuns) commented on 2013-11-28T07:52:06Z

Whatever it is, current behavior is extremely confusing for newbies as one may expect it to actually work in example like provided in the first post.

@dlangBugzillaToGithub
Copy link
Author

bearophile_hugs commented on 2013-11-28T08:02:54Z

See also Issue 3934

@dlangBugzillaToGithub
Copy link
Author

andrej.mitrovich (@AndrejMitrovic) commented on 2014-04-22T21:17:36Z

*** Issue 12299 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

andrej.mitrovich (@AndrejMitrovic) commented on 2014-04-22T21:17:49Z

*** Issue 12257 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

rburners commented on 2015-06-04T02:30:13Z

phobos PR https://github.com/D-Programming-Language/phobos/pull/2995

is sort of blocked by:

template RefType(T) alias RefType = ref T;

not working anymore

@dlangBugzillaToGithub
Copy link
Author

qs.il.paperinik commented on 2021-01-10T00:24:27Z

The grammar allows this to make

alias RefDG = ref int delegate();

legal. Having ref be accepted but with no effect is nothing special about the D compiler. It accepts a lot of annotations that have no effect.

The question which cases are accepts-invalid and which are not is mostly a matter of taste.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant