Bug 12545 – An object with .init breaks std.range.ElementType

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-08T07:01:11Z
Last change time
2024-12-01T16:20:45Z
Assigned to
No Owner
Creator
Adam D. Ruppe
Depends on
7066
See also
https://issues.dlang.org/show_bug.cgi?id=7066
Moved to GitHub: phobos#10045 →

Comments

Comment #0 by destructionator — 2014-04-08T07:01:11Z
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.
Comment #1 by robert.schadek — 2024-12-01T16:20:45Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10045 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB