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
Conversation
Thanks for your pull request, @NilsLankila! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#11604" |
@@ -0,0 +1,21 @@ | |||
struct F | |||
{ | |||
alias thisTup = typeof(this).tupleof; |
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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. Usetypeof(this)
instead
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
I'm gonna close this as the author has abandoned it. Anyone can pick it up. |
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 anAliasSeq
To advocate the change, note that the problem was noticed several times over the past years: