April 08, 2014 [Issue 12545] New: An object with .init breaks std.range.ElementType | ||||
---|---|---|---|---|
| ||||
https://d.puremagic.com/issues/show_bug.cgi?id=12545 Summary: An object with .init breaks std.range.ElementType Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: minor Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: destructionator@gmail.com --- Comment #0 from Adam D. Ruppe <destructionator@gmail.com> 2014-04-08 07:01:11 PDT --- import std.range; struct Foo { /* same with class btw */ void init(int a) { } } void main() { Foo[] a; pragma(msg, ElementType!(typeof(a))); // void(int a) auto s = stride(a, 3); // * } * std/range.d(2188): Error: variable std.range.stride!(Foo[]).stride.Result.front.val cannot be declared to be a function Since ElementType checks Type.init.front.init, it gets a function type instead of the element type - void(int) instead of Foo. Then, stride (among many others) uses ElementType!Range in the function definitions, we get big errors when the higher order range functions are declared with them in places. I'm not sure if this is a bug per se, and is easily worked around by renaming the function from init to anything else, but it is pretty easy to break and hard to track down the cause if you don't have an idea of the .init idiom used in phobos. I kinda feel that declaring a member called init ought to be disallowed, so Type.init can be trusted in all code. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation