Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #402 (closed defect: invalid)

Opened 14 years ago

Last modified 14 years ago

Associative Array indexing doesn't work.

Reported by: Brix Assigned to: ChristianK
Priority: major Milestone:
Component: unspecified Version: hg tip
Keywords: Cc:

Description

module testaa;

import tango.io.Stdout;

void main(char[][] args)
{
	//From first example @ http://digitalmars.com/d/1.0/arrays.html#associative.
	int[char[]] b;
	b["hello"] = 3;
	Stdout(b["hello"])(); //Line 10.
}
testaa.d(10): Error: Stdout is used as a type
testaa.d(10): Error: Stdout is used as a type
testaa.d(10): Error: Integer constant expression expected instead of "hello"
testaa.d(10): Error: Integer constant expression expected instead of cast(ulong)"hello"
testaa.d(10): Error: can't have array of void()
testaa.d(10): Error: Integer constant expression expected instead of cast(ulong)"hello"
testaa.d(10): Error: Integer constant expression expected instead of cast(ulong)"hello"
testaa.d(10): Error: Integer constant expression expected instead of cast(ulong)"hello"
testaa.d(10): Error: declaration testaa.main.b is already defined

Change History

03/16/10 04:23:44 changed by Brix

Hmm this works, so I guess the bug should be renamed, but I'm not really sure what is going on:

module testaa;

import tango.io.Stdout;

void main(char[][] args)
{
	//From first example @ http://digitalmars.com/d/1.0/arrays.html#associative.
	int[char[]] b;
	b["hello"] = 3;
	auto val = b["hello"]; //Line 10.
	Stdout(val)();
}

03/17/10 06:53:13 changed by ChristianK

  • status changed from new to closed.
  • resolution set to invalid.

This is a DMDFE problem, please file it in the DMD bugzilla.

Reduced example:

struct Stdout {
  static Stdout opCall(int i = 0) { Stdout s; return s; }
}

void main() {
  int[char[]] b;

  Stdout(b["hello"])(); // error, DMDFE thinks you want to declare b
                        // of type Stdout["hello"]

  int (funcptr[4])(); // declares int[4] funcptr;
}

03/17/10 14:21:39 changed by Brix

Copyright © 2008, LDC Development Team.