Re: Scoped import bug?
On Thursday, 9 May 2013 at 09:52:12 UTC, Kenji Hara wrote: On Thursday, 9 May 2013 at 05:01:15 UTC, Mike Linford wrote: I'm not sure whether or not I've encountered a bug or whether my understanding of scoped imports is just faulty. blah.d: 1 module blah; 2 3 version(A) 4 { 5import std.range; 6 } 7 8 struct Blah(R) 9 { 10version(B) 11{ 12 import std.range; 13} 14static assert(isInputRange!R); 15 16void blah(R r) 17{ 18 version(C) 19 { 20 assert(r.front == 'h'); 21 } 22} 23 } 24 25 void main() 26 { 27Blah!string blah; 28blah.blah(hello); 29 } Results: rdmd -version=A -version=C blah Compiles fine. Module-level import works for the static assert on line 14 and the runtime assert on line 20 rdmd -version=B blah Compiles fine! Struct-level import works for the static assert on line 14 rdmd -version=B -version=C blah Fails to compile. I get the following error messages: blah.d(20): Error: no property 'front' for type 'string' blah.d(27): Error: template instance blah.Blah!(string) error instantiating So it appears that when my import is at the struct level like line 12 I'm able to use the static assert but *not* the runtime assert. Why cant the function Blah.blah() find the array implementation of front? This is a known UFCS name look-up issue. In 2.063dev, the bug is fixed. Please wait the release. Kenji Hara Thank you for the explanation. Was this the issue? http://d.puremagic.com/issues/show_bug.cgi?id=6185
Scoped import bug?
I'm not sure whether or not I've encountered a bug or whether my understanding of scoped imports is just faulty. blah.d: 1 module blah; 2 3 version(A) 4 { 5import std.range; 6 } 7 8 struct Blah(R) 9 { 10version(B) 11{ 12 import std.range; 13} 14static assert(isInputRange!R); 15 16void blah(R r) 17{ 18 version(C) 19 { 20 assert(r.front == 'h'); 21 } 22} 23 } 24 25 void main() 26 { 27Blah!string blah; 28blah.blah(hello); 29 } Results: rdmd -version=A -version=C blah Compiles fine. Module-level import works for the static assert on line 14 and the runtime assert on line 20 rdmd -version=B blah Compiles fine! Struct-level import works for the static assert on line 14 rdmd -version=B -version=C blah Fails to compile. I get the following error messages: blah.d(20): Error: no property 'front' for type 'string' blah.d(27): Error: template instance blah.Blah!(string) error instantiating So it appears that when my import is at the struct level like line 12 I'm able to use the static assert but *not* the runtime assert. Why cant the function Blah.blah() find the array implementation of front?
D1 and D2 differences
How up to date is http://digitalmars.com/d/2.0/features2.html ? If it's old, what differences can people think of off the tops of their heads that are not listed?
Re: Contracts or Exceptions?
Thanks for the responses, everybody. They were helpful :-) -- --Mike Linford
Re: Unit tests in libraries?
On Mon, 16 Aug 2010 08:37:35 -0400, Steven Schveighoffer wrote: On Sat, 14 Aug 2010 23:35:54 -0400, Mike Linford mike.linford@gmail.com wrote: Is this a bug? Unit tests do not seem to work in libraries. I'm using dmd 1.062 for linux. mylib.d : module mylib; void blah() { } unittest { assert(false); } main.d : module main; import mylib; void main() { blah(); } The unit test does not get run when compiled as: dmd -lib mylib.d dmd main.d mylib.a But does get run when compiled as dmd main.d mylib.d Is this the intended behavior for unit tests in libraries? Did you pass -unittest to dmd? It needs to be there when compiling the file that contains unit tests. I'm surprised unittests run at all with those compile lines. -Steve Haha, whoops, forgot to mention that I DID indeed include -unittest in all compile lines. -- Mike Linford
Unit tests in libraries?
Is this a bug? Unit tests do not seem to work in libraries. I'm using dmd 1.062 for linux. mylib.d : module mylib; void blah() { } unittest { assert(false); } main.d : module main; import mylib; void main() { blah(); } The unit test does not get run when compiled as: dmd -lib mylib.d dmd main.d mylib.a But does get run when compiled as dmd main.d mylib.d Is this the intended behavior for unit tests in libraries? -- Mike Linford
Re: const(type) vs. const type
Thanks for the responses guys, I appreciate it. -- Mike Linford
const(type) vs. const type
I'm playing with QtD, and I tried to override a QWidget's sizeHint() function, which is declared as const QSize sizeHint(). I tried to override it by declaring my function as override const(QSize) sizeHint () . I got a compiler error that it was not covariant with const QSize, and when I changed it to that it worked fine. I've skimmed through the documentation but don't understand what the difference is. Any help? -- Mike Linford
Re: Templates with strings
On Sun, 04 Jul 2010 00:43:50 +, BCS wrote: Hello Mike, I'm trying to compile the following file. Can somebody explain to me how I can rewrite it so that I don't get Error: non-constant expression? All I'm trying to do is create, using templates, a string of all characters between two given characters: 1) where did you get that error? (I'm lazy, sorry) 2) is there a reason you don't use CTFE? dchar[] Between(dchar start, dchar stop) { if(start stop) { auto t = start; start = stop; stop = t; } dchar[] ret; for(dchar d = start; d=stop; d++) ret ~= d; return ret; } import std.stdio; void Go(dchar[] s)(){writef(%s\n, s); } void main(){Go!(Between('a','g'))();} 1 module ua; 2 3 template dcharInterval(immutable(dchar) start, immutable(dchar) stop) 4 { 5static assert(stop = start); 6static if(start == stop) 7 dstring dcharInterval = [start]; 8else 9 dstring dcharInterval = [start] ~ dcharInterval!(start + 1, stop); 10 } 11 12 dstring LATIN = \u00AAd ~ \u00BAd ~ dcharInterval!(0x00C0, 0x00D6); 13 Thanks. Hi BCS, 1. I was getting that error on lines 9 and 12. I got it a couple dozen times (I assume once for each template instance). 2. The reason I don't use CTFE is because I don't know how to be certain its been called at compile time. Apparently using a result in a template like you did will accomplish that, but is there a way I can be sure without making up bogus empty templates? Thanks. -- Mike Linford
Templates with strings
I'm trying to compile the following file. Can somebody explain to me how I can rewrite it so that I don't get Error: non-constant expression? All I'm trying to do is create, using templates, a string of all characters between two given characters: 1 module ua; 2 3 template dcharInterval(immutable(dchar) start, immutable(dchar) stop) 4 { 5static assert(stop = start); 6static if(start == stop) 7 dstring dcharInterval = [start]; 8else 9 dstring dcharInterval = [start] ~ dcharInterval!(start + 1, stop); 10 } 11 12 dstring LATIN = \u00AAd ~ \u00BAd ~ dcharInterval!(0x00C0, 0x00D6); 13 Thanks. -- Mike Linford
aliasing templates
I remember that if you alias a template, it is instantiated and is compiled into the object file/library. What I can't remember is where in the d spec this behavior is described. Can anyone help me out? -- Mike L.