digitalmars.D.bugs - Compiler does not always honor typedef contract
- Roberto Mariottini (24/24) Dec 05 2005 Hi,
- Walter Bright (15/39) Dec 05 2005 Yes. Using typedefs would be useless if this didn't work.
- Roberto Mariottini (18/35) Dec 07 2005 I understand, even if I disagree. I am for strong typing, for this case ...
- Thomas Kuehne (19/34) Dec 18 2005 -----BEGIN PGP SIGNED MESSAGE-----
Hi,
Tried with DMD v0.141 on Windows XP:
typedef int apples;
typedef int pears;
int main(char[][] args)
{
int i = 13;
apples a = 13; // OK (?)
apples a2 = i; // cannot implicitly convert expression (i) of type int to apples
pears p = 13; // OK (?)
pears p2 = i; // cannot implicitly convert expression (i) of type int to pears
a = a + a; // OK
a = a + 1; // OK (?)
a = a + i; // OK (?)
a = a + p; // OK (???)
a = 1 + a; // cannot implicitly convert expression (1 + a) of type int to apples
a = i + a; // cannot implicitly convert expression (i + a) of type int to apples
a = p + a; // cannot implicitly convert expression (p + a) of type pears to
apples
a = cast(apples) 1 + a; // OK
a = cast(apples) i + a; // OK
a = cast(apples) p + a; // OK
return 0;
}
Dec 05 2005
"Roberto Mariottini" <Roberto_member pathlink.com> wrote in message news:dn1gtg$145u$1 digitaldaemon.com...Hi, Tried with DMD v0.141 on Windows XP: typedef int apples; typedef int pears; int main(char[][] args) { int i = 13; apples a = 13; // OK (?)Yes. Using typedefs would be useless if this didn't work.apples a2 = i; // cannot implicitly convert expression (i) of type int toapples Yes. Otherwise there is no point to typedef's. <g>pears p = 13; // OK (?) pears p2 = i; // cannot implicitly convert expression (i) of type int topearsa = a + a; // OK a = a + 1; // OK (?)Yes.a = a + i; // OK (?)This should be allowed.a = a + p; // OK (???)This should not be allowed.a = 1 + a; // cannot implicitly convert expression (1 + a) of type int toapples This should be allowed.a = i + a; // cannot implicitly convert expression (i + a) of type int toapples This should be allowed.a = p + a; // cannot implicitly convert expression (p + a) of type pearstoapplesThis should not be allowed.a = cast(apples) 1 + a; // OK a = cast(apples) i + a; // OK a = cast(apples) p + a; // OK return 0; }
Dec 05 2005
In article <dn203h$1q0n$1 digitaldaemon.com>, Walter Bright says...[...]I understand, even if I disagree. I am for strong typing, for this case I prefer a constructor approach, like: apples a = apples(13); And what about function parameter passing? void f (apples x) { ... } .. f(13); // is this allowed? In my opinion this should be an error.typedef int apples; typedef int pears; int main(char[][] args) { int i = 13; apples a = 13; // OK (?)Yes. Using typedefs would be useless if this didn't work.Indeed. [...]apples a2 = i; // cannot implicitly convert expression (i) of type int toapples Yes. Otherwise there is no point to typedef's. <g>I disagree, see above.a = a + 1; // OK (?)Yes.How this is different from: apples a2 = i; For consistency this should be an error as well.a = a + i; // OK (?)This should be allowed.Obviously. Ciaoa = a + p; // OK (???)This should not be allowed.
Dec 07 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Walter Bright schrieb am 2005-12-05:"Roberto Mariottini" <Roberto_member pathlink.com> wrote in message news:dn1gtg$145u$1 digitaldaemon.com...[snip]Hi, Tried with DMD v0.141 on Windows XP: typedef int apples; typedef int pears; int main(char[][] args) { int i = 13; apples a = 13; // OK (?)[snip] Where is this documented? Added to DStress as http://dstress.kuehne.cn/nocompile/t/typedef_09_A.d http://dstress.kuehne.cn/nocompile/t/typedef_09_B.d http://dstress.kuehne.cn/nocompile/t/typedef_09_C.d http://dstress.kuehne.cn/run/t/typedef_09_D.d http://dstress.kuehne.cn/run/t/typedef_09_E.d http://dstress.kuehne.cn/run/t/typedef_09_F.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDpg603w+/yD4P9tIRAuFsAJ91gp/Tk8VHFIzVV187XZ+jzRuCFgCeNEOA gSVYSeOvd1yjImiYjujOx18= =kQg3 -----END PGP SIGNATURE-----a = i + a; // cannot implicitly convert expression (i + a) of type int toapples This should be allowed.
Dec 18 2005









Roberto Mariottini <Roberto_member pathlink.com> 