Bug 850 – we need (*type).property to refer to property if we use typedef
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-01-14T20:00:26Z
Last change time
2018-10-19T04:53:36Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
david
Comments
Comment #0 by davidl — 2007-01-14T20:00:26Z
module test.test;
class test
{
int myMember;
}
typedef test *ptest;
void main()
{
ptest k;
k.myMember = 1;
}
dmd complains:
test.d(10): Error: no property 'myMember' for type 'test*'
test.d(10): Error: constant (k).myMember is not an lvalue
typedef test *ptest; <--- the problem is here. I think it's
something related to dmd's strong type mechanism.
alias test *ptest; // this would work fine
i don't know if i can call this a bug , but at least the
compile message should be nicer. Leave to u to decide either
this should be a bug or an enhancement.
Comment #1 by smjg — 2007-01-15T07:37:38Z
Because of the 'is a' principle of typedefs, this should work. I call this a bug.
Comment #3 by ellery-newcomer — 2011-12-08T18:13:43Z
alias doesn't seem to be any better.
dmd 2.056 64 bit linux,
alias JNINativeInterface_* JNIEnv;
struct JNINativeInterface_ {
int FindClass;
}
void main(){
JNIEnv* env;
auto x = env.FindClass;
}
compiled results in
foo.d(8): Error: no property 'FindClass' for type 'JNINativeInterface_*'
Comment #4 by luk.wrzosek — 2012-02-15T08:31:12Z
Checked dmd(In reply to comment #3)
> alias doesn't seem to be any better.
>
> dmd 2.056 64 bit linux,
>
> alias JNINativeInterface_* JNIEnv;
>
> struct JNINativeInterface_ {
> int FindClass;
> }
> void main(){
> JNIEnv* env;
> auto x = env.FindClass;
> }
>
> compiled results in
>
> foo.d(8): Error: no property 'FindClass' for type 'JNINativeInterface_*'
This case is wrong.
variable env is of type JNINativeInterface_** so compiler rejects invalid code correctly.
Comment #5 by pro.mathias.lang — 2018-10-19T04:53:36Z
```
alias JNINativeInterface_* JNIEnv;
struct JNINativeInterface_ {
int FindClass;
}
void main(){
JNIEnv env;
auto x = env.FindClass;
}
```
Compiles just fine. Since we don't have Typedef anymore, closing.