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

fix issue 21187 - allow to alias directly .tupleof #11604

Closed
wants to merge 1 commit into from
Closed

fix issue 21187 - allow to alias directly .tupleof #11604

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 22, 2020

It is actually not a good idea to use .tupleof[index] because the whole tuple is regenerated for each use.
But for now alias id = T.tupleof is not allowed which is odd so this PR allows the alias, without using an AliasSeq

To advocate the change, note that the problem was noticed several times over the past years:

@ghost ghost added the Enhancement label Aug 22, 2020
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @NilsLankila!

Bugzilla references

Auto-close Bugzilla Severity Description
21187 enhancement .tupleof should be directly usable as alias

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11604"

src/dmd/dsymbolsem.d Outdated Show resolved Hide resolved
@@ -0,0 +1,21 @@
struct F
{
alias thisTup = typeof(this).tupleof;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing this example to:

Suggested change
alias thisTup = typeof(this).tupleof;
alias thisTup = this.tupleof;

as accessing this.{a, b, c, d} through a type looks quite confusing. I don't know if it's late to change this, but I'd expect that only this.tupleof (or .tupleof on any object instance (class or struct, doesn't matter)) would be able to access instance members.

typeof(this).tupleof should, of course, continue working, but I expect it to only yield static info about the type - a sequnece of types, (and their names and default values) and not a direct reference to struct/class object members.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I did the right thing, what you propose is even an error since a few release (this or super used as a type)

Error: Using this as a type is obsolete. Use typeof(this) instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW when this is required, the compiler can rewrite a VarExp /CallExp to a DotVarExp that adds the missing this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: Using this as a type is obsolete. Use typeof(this) instead

I'm aware of https://github.com/dlang/dmd/pull/9711/files, however I think it's a bug to get this error here, as in this context, typeof(this).tupleof should be equivalent to F.tupleof, which I don't see how it could be allowed to reference instance (non-static) members. Whether you access typeof(this) inside of a class or struct, or F.tupleof (where F is their name for example) from outside must have the same semantics in the same module (I don't want
to get into private / protected, but for now even in different modules).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how it could be allowed to reference instance (non-static) members

but .tupleof doesn't even return static members

@RazvanN7 RazvanN7 added Orphaned The author of the PR is no longer available and this PR can be adopted by anyone. Phantom Zone Has value/information for future work, but closed for now stalled labels Jan 12, 2021
@RazvanN7
Copy link
Contributor

I'm gonna close this as the author has abandoned it. Anyone can pick it up.

@RazvanN7 RazvanN7 closed this Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Orphaned The author of the PR is no longer available and this PR can be adopted by anyone. Phantom Zone Has value/information for future work, but closed for now stalled
Projects
None yet
4 participants