www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Weird writeln behavior with associative arrays

reply Jens Mueller <jens.k.mueller gmx.de> writes:
Hi,

this program
import std.stdio;

void main() {
	double[string] foo;
	foo["test"] = 10;
	foo["atadfest"] = 10;
	// fails if foo.length > 1
	writeln(foo);
}

fails with:
phobos/std/format.d(1088): Enforcement failed

Am I not allowed to to this? If I have only one element, then it works
as expected. If I change double to int, then I get "test:10 a:10". So
somehow only the first character is displayed. Maybe a phobos bug? Any
ideas?

I'm using Linux and latest dmd.
$ dmd | head -n1
Digital Mars D Compiler v2.049

Jens
Oct 15 2010
next sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/15/2010 10:04 AM, Jens Mueller wrote:
 Hi,

 this program
 import std.stdio;

 void main() {
 	double[string] foo;
 	foo["test"] = 10;
 	foo["atadfest"] = 10;
 	// fails if foo.length>  1
 	writeln(foo);
 }

 fails with:
 phobos/std/format.d(1088): Enforcement failed

 Am I not allowed to to this? If I have only one element, then it works
 as expected. If I change double to int, then I get "test:10 a:10". So
 somehow only the first character is displayed. Maybe a phobos bug? Any
 ideas?

 I'm using Linux and latest dmd.
 $ dmd | head -n1
 Digital Mars D Compiler v2.049

 Jens

This is odd. I can't reproduce your bug. Line 1088 is: enforce(f.spec == 's'); because indeed the default formatting specifier is "%s". Could there be a lack of sync between the compiled library and the import files? For example, if the layout of the internal format structure has changed, then f.spec will have the wrong offset. Andrei
Oct 15 2010
parent Peter Alexander <peter.alexander.au gmail.com> writes:
On 15/10/10 4:30 PM, Denis Koroskin wrote:
 On Fri, 15 Oct 2010 19:22:08 +0400, Andrei Alexandrescu
 This is odd. I can't reproduce your bug. Line 1088 is:

 Andrei

I can reproduce it on Windows.

And I can reproduce on Mac OS X.
Oct 15 2010
prev sibling next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Fri, 15 Oct 2010 19:22:08 +0400, Andrei Alexandrescu  
<SeeWebsiteForEmail erdani.org> wrote:

 On 10/15/2010 10:04 AM, Jens Mueller wrote:
 Hi,

 this program
 import std.stdio;

 void main() {
 	double[string] foo;
 	foo["test"] = 10;
 	foo["atadfest"] = 10;
 	// fails if foo.length>  1
 	writeln(foo);
 }

 fails with:
 phobos/std/format.d(1088): Enforcement failed

 Am I not allowed to to this? If I have only one element, then it works
 as expected. If I change double to int, then I get "test:10 a:10". So
 somehow only the first character is displayed. Maybe a phobos bug? Any
 ideas?

 I'm using Linux and latest dmd.
 $ dmd | head -n1
 Digital Mars D Compiler v2.049

 Jens

This is odd. I can't reproduce your bug. Line 1088 is: enforce(f.spec == 's'); because indeed the default formatting specifier is "%s". Could there be a lack of sync between the compiled library and the import files? For example, if the layout of the internal format structure has changed, then f.spec will have the wrong offset. Andrei

I can reproduce it on Windows.
Oct 15 2010
prev sibling parent reply "Masahiro Nakagawa" <repeatedly gmail.com> writes:
On Sat, 16 Oct 2010 00:04:22 +0900, Jens Mueller <jens.k.mueller gmx.de>  
wrote:

 Hi,

 this program
 import std.stdio;

 void main() {
 	double[string] foo;
 	foo["test"] = 10;
 	foo["atadfest"] = 10;
 	// fails if foo.length > 1
 	writeln(foo);
 }

 fails with:
 phobos/std/format.d(1088): Enforcement failed

 Am I not allowed to to this? If I have only one element, then it works
 as expected. If I change double to int, then I get "test:10 a:10". So
 somehow only the first character is displayed. Maybe a phobos bug? Any
 ideas?

 I'm using Linux and latest dmd.
 $ dmd | head -n1
 Digital Mars D Compiler v2.049

 Jens

SHOO has already fixed this problem. http://www.dsource.org/projects/phobos/changeset/2030
Oct 15 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/15/10 14:21 CDT, Masahiro Nakagawa wrote:
 SHOO has already fixed this problem.

 http://www.dsource.org/projects/phobos/changeset/2030

Great, thanks Shoo and Masahiro. One thing - now firstTime is not needed anymore so it could go away. Andrei
Oct 15 2010