digitalmars.D - Is this a bug?
- Rene Zwanenburg (24/24) Jun 26 2014 I /think/ this is a bug, but I'm not 100% sure. The following
- John Colvin (13/37) Jun 26 2014 I don't think that's a bug, but I think the template constraint
- John Colvin (3/51) Jun 26 2014 Ah, it appears that this has already been done. Good.
- hane (2/26) Jun 26 2014 DMD 2.066(git head) compiled both without error.
- Rene Zwanenburg (2/3) Jun 26 2014 Thanks for checking!
- Meta (3/27) Jun 26 2014 Yes, this is a bug. This code should work. If it doesn't compile
- Rene Zwanenburg (3/5) Jun 26 2014 Apparently it does. I'm not set up to build DMD myself so I'm
I /think/ this is a bug, but I'm not 100% sure. The following compiles without any problems, as it should: import std.typecons; alias Handle(T) = RefCounted!(T, RefCountedAutoInitialize.no); auto initialized(T)() if(is(T == RefCounted!S, S...)) { T refCounted; refCounted.refCountedStore.ensureInitialized(); return refCounted; } alias S = Handle!S_Impl; struct S_Impl { } void main() { auto s = initialized!S; } Change 'initialized' to: auto initialized(T)() if(is(T == Handle!S, S)) and the compiler will complain: Error: template instance test.initialized!(RefCounted!(S_Impl, cast(RefCountedAutoInitialize)0)) does not match template declaration initialized(T)() if (is(T == Handle!S, S))
Jun 26 2014
On Thursday, 26 June 2014 at 10:09:53 UTC, Rene Zwanenburg wrote:I /think/ this is a bug, but I'm not 100% sure. The following compiles without any problems, as it should: import std.typecons; alias Handle(T) = RefCounted!(T, RefCountedAutoInitialize.no); auto initialized(T)() if(is(T == RefCounted!S, S...)) { T refCounted; refCounted.refCountedStore.ensureInitialized(); return refCounted; } alias S = Handle!S_Impl; struct S_Impl { } void main() { auto s = initialized!S; } Change 'initialized' to: auto initialized(T)() if(is(T == Handle!S, S)) and the compiler will complain: Error: template instance test.initialized!(RefCounted!(S_Impl, cast(RefCountedAutoInitialize)0)) does not match template declaration initialized(T)() if (is(T == Handle!S, S))I don't think that's a bug, but I think the template constraint itself shouldn't be legal to write. It's not possible to support the general case of a template A in is(T == A!X, X) as it would require following all possible instantiation paths of A. The compiler could keep track of how a type was created on a per-identifier basis and then use that to check, but that would mean rejecting types that had a different instantiation path (e.g. is(RefCounted!(int, RefCountedAutoInitialize.no) == Handle!S, S) == false). What might be feasible would be to extend is(T == A!X, X) to work with simple tmeplates and paramterised aliases like Handle, while statically disallowing more complicated / undecidable ones..
Jun 26 2014
On Thursday, 26 June 2014 at 12:38:40 UTC, John Colvin wrote:On Thursday, 26 June 2014 at 10:09:53 UTC, Rene Zwanenburg wrote:Ah, it appears that this has already been done. Good. If I've misunderstood the situation, somebody please correct me.I /think/ this is a bug, but I'm not 100% sure. The following compiles without any problems, as it should: import std.typecons; alias Handle(T) = RefCounted!(T, RefCountedAutoInitialize.no); auto initialized(T)() if(is(T == RefCounted!S, S...)) { T refCounted; refCounted.refCountedStore.ensureInitialized(); return refCounted; } alias S = Handle!S_Impl; struct S_Impl { } void main() { auto s = initialized!S; } Change 'initialized' to: auto initialized(T)() if(is(T == Handle!S, S)) and the compiler will complain: Error: template instance test.initialized!(RefCounted!(S_Impl, cast(RefCountedAutoInitialize)0)) does not match template declaration initialized(T)() if (is(T == Handle!S, S))I don't think that's a bug, but I think the template constraint itself shouldn't be legal to write. It's not possible to support the general case of a template A in is(T == A!X, X) as it would require following all possible instantiation paths of A. The compiler could keep track of how a type was created on a per-identifier basis and then use that to check, but that would mean rejecting types that had a different instantiation path (e.g. is(RefCounted!(int, RefCountedAutoInitialize.no) == Handle!S, S) == false). What might be feasible would be to extend is(T == A!X, X) to work with simple tmeplates and paramterised aliases like Handle, while statically disallowing more complicated / undecidable ones..
Jun 26 2014
On Thursday, 26 June 2014 at 10:09:53 UTC, Rene Zwanenburg wrote:I /think/ this is a bug, but I'm not 100% sure. The following compiles without any problems, as it should: import std.typecons; alias Handle(T) = RefCounted!(T, RefCountedAutoInitialize.no); auto initialized(T)() if(is(T == RefCounted!S, S...)) { T refCounted; refCounted.refCountedStore.ensureInitialized(); return refCounted; } alias S = Handle!S_Impl; struct S_Impl { } void main() { auto s = initialized!S; } Change 'initialized' to: auto initialized(T)() if(is(T == Handle!S, S)) and the compiler will complain: Error: template instance test.initialized!(RefCounted!(S_Impl, cast(RefCountedAutoInitialize)0)) does not match template declaration initialized(T)() if (is(T == Handle!S, S))DMD 2.066(git head) compiled both without error.
Jun 26 2014
On Thursday, 26 June 2014 at 12:52:54 UTC, hane wrote:DMD 2.066(git head) compiled both without error.Thanks for checking!
Jun 26 2014
On Thursday, 26 June 2014 at 10:09:53 UTC, Rene Zwanenburg wrote:I /think/ this is a bug, but I'm not 100% sure. The following compiles without any problems, as it should: import std.typecons; alias Handle(T) = RefCounted!(T, RefCountedAutoInitialize.no); auto initialized(T)() if(is(T == RefCounted!S, S...)) { T refCounted; refCounted.refCountedStore.ensureInitialized(); return refCounted; } alias S = Handle!S_Impl; struct S_Impl { } void main() { auto s = initialized!S; } Change 'initialized' to: auto initialized(T)() if(is(T == Handle!S, S)) and the compiler will complain: Error: template instance test.initialized!(RefCounted!(S_Impl, cast(RefCountedAutoInitialize)0)) does not match template declaration initialized(T)() if (is(T == Handle!S, S))Yes, this is a bug. This code should work. If it doesn't compile with Git HEAD, you should file a bug report.
Jun 26 2014
On Thursday, 26 June 2014 at 13:25:00 UTC, Meta wrote:Yes, this is a bug. This code should work. If it doesn't compile with Git HEAD, you should file a bug report.Apparently it does. I'm not set up to build DMD myself so I'm always just using the latest release.
Jun 26 2014