digitalmars.D.bugs - [Issue 9563] New: (2.062) typeof(T[0]) no longer works with array T's
- d-bugmail puremagic.com (44/44) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9563
- d-bugmail puremagic.com (16/16) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9563
- d-bugmail puremagic.com (24/27) Feb 21 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9563
- d-bugmail puremagic.com (26/38) Feb 22 2013 I am not with DMD 2.062. This code compiles without any error and prints...
- d-bugmail puremagic.com (13/29) Feb 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9563
- d-bugmail puremagic.com (16/16) Feb 22 2013 http://d.puremagic.com/issues/show_bug.cgi?id=9563
http://d.puremagic.com/issues/show_bug.cgi?id=9563 Summary: (2.062) typeof(T[0]) no longer works with array T's Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: regression Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: siegelords_abode yahoo.com Both invocations of ElemTypeOf used to work fine with DMD 2.061 but with DMD 2.062 only the class one works. Either none of them should work, or preferably both should work as they had since D1: template ElemTypeOf( T ) { alias typeof(T[0]) ElemTypeOf; } class A { int opIndex(size_t i) { return 0; } } void main() { ElemTypeOf!(A) a; ElemTypeOf!(int[]) b; static assert(is(typeof(a) == int)); static assert(is(typeof(b) == int)); } With dmd 2.062 the second invocation now gives the error: test.d(3): Error: argument int[][0LU] to typeof is not an expression test.d(3): Error: argument int[][0LU] to typeof is not an expression test.d(17): Error: template instance test.ElemTypeOf!(int[]) error instantiating test.d(20): Error: static assert (is(_error_ == int)) is false -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9563 Marco Leise <Marco.Leise gmx.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |Marco.Leise gmx.de You made me smile. I recently needed ElementType! in my code for arrays. I had almost written a simple template, but remembered that Phobos had it already. And I thought "I better use the Phobos one, that's sure to still work in the future. Not that it's likely that typeof(T[0]) breaks anytime soon... but still." Sometimes you have these gut feelings you can't even explain to co-workers. Sorry for the noise. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9563 monarchdodra gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra gmail.comBoth invocations of ElemTypeOf used to work fine with DMD 2.061 but with DMD 2.062 only the class one works. Either none of them should work, or preferably both should work as they had since D1:What do you mean "only the class one works"? I'm getting a failure for both asserts. Furthermore, I expect a failure. Your ElemTypeOf simply declares a static array of size 0 of your type, it is not actually calling opIndex. Then combining it with calling "typeof" on something that is already a type, makes this dobly wrong code. This worked in 2.060, but was fixed starting in 2.061. Try something like this: template ElemTypeOf( T ) { static private T t = T.init; alias typeof(t[0]) ElemTypeOf; } Or better yet, std.range's ElementType or ElementEncodingType. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 21 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9563What do you mean "only the class one works"? I'm getting a failure for both asserts.I am not with DMD 2.062. This code compiles without any error and prints "int": template ElemTypeOf( T ) { alias typeof(T[0]) ElemTypeOf; } class A { int opIndex(size_t i) { return 0; } } void main() { ElemTypeOf!(A) a; pragma(msg, typeof(a).stringof); static assert(is(typeof(a) == int)); }This worked in 2.060, but was fixed starting in 2.061. Try something like this: template ElemTypeOf( T ) { static private T t = T.init; alias typeof(t[0]) ElemTypeOf; }I guess that works (with some simplification of course), although the existence of a workaround does not negate the existence of the regression.Or better yet, std.range's ElementType or ElementEncodingType.Not using Phobos. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9563My bad, I must have botched the test. That does indeed work in 2.061, so was broken in 2.062.What do you mean "only the class one works"? I'm getting a failure for both asserts.I am not with DMD 2.062. This code compiles without any error and prints "int":This worked in 2.060, but was fixed starting in 2.061.Well, as I said, I think this is not a matter of regression and workaround, but rather wrong code finally getting rejected, and new and correct code being deployed to replace it. In any case, I'll let one of the more compiler knowledgeable guys (Kenji? Walter) give you definitive answer. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------Try something like this: template ElemTypeOf( T ) { static private T t = T.init; alias typeof(t[0]) ElemTypeOf; }I guess that works (with some simplification of course), although the existence of a workaround does not negate the existence of the regression.
Feb 22 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9563 Steven Schveighoffer <schveiguy yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |schveiguy yahoo.com Resolution| |INVALID 08:21:07 PST --- This is indeed a bug that was fixed. T[0] is applying index to the type, not an instance of the type. I wouldn't expect typeof(T[0]) to work at all, it's like saying typeof(int) (which doesn't compile), typeof converts an expression into its type. You should be able to do typeof(T.init[0]). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 22 2013