Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #323 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Unable to create maps with numeric keys.

Reported by: Ansible Assigned to: kris
Priority: normal Milestone: 0.97 RC 1
Component: Core Functionality Version: trunk
Keywords: Map TreeMap HashMap null Cc:

Description

Creating a TreeMap?!(double, myclass)() or HashMap?!(double, myclass)() results in compile problems where double is compared to null. One place this happens is in MapCollection?.d, line 90. Not sure how to fix that one.

Another place is TreeMap?.d line 317 and 323, where IMO 'return null' could be replaced with a NoSuchElementException? to avoid the cast from null to double.

Attachments

TreeMap.d (21.2 kB) - added by Ansible on 03/11/07 15:14:12.
TreeMap? with exceptions

Change History

03/11/07 15:14:12 changed by Ansible

  • attachment TreeMap.d added.

TreeMap? with exceptions

03/11/07 15:22:40 changed by larsivi

  • owner changed from sean to kris.
  • milestone set to 0.97 RC 1.

#322 marked as duplicate

03/12/07 14:31:56 changed by kris

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

keyOf() returns a bool instead, and takes an additional argument.

Thanks for the report!

03/12/07 17:41:57 changed by Ansible

Hey, one more thing, in MapView?.d:

public bool keyOf(K key, V value);

should be:

public bool keyOf(inout K key, V value);

Its causing an "interface function Map.keyOf isn't implemented" error.

03/12/07 17:56:39 changed by kris

ach ... I don't understand how the compilation let that one pass ... I can't get it to error, for some reason, when enabling -debug=Test on that package. Oh well; thanks!

03/16/07 21:51:48 changed by Ansible

  • status changed from closed to reopened.
  • resolution deleted.

One more issue with this fix, there's this code:

protected final bool isValidKey(K key) { /*

static if (is (T : Object))

{ if (key is null)

return false;

} */

return true;

}

With my DMD compiler, it has a problem with the 'key is null', even though I guess its supposed to be protected by the static if. Maybe it should be if (is (key : Object) ? Anyway I commented the whole check out.

03/16/07 22:36:26 changed by Ansible

wups, forgot to mention that is in MapCollection?.d. Changed it to this and it seems to work ok, not sure if this is right though:

        protected final bool isValidKey(K key)
        {
                static if (is (K : Object))
                          {
                          if (key is null)
                              return false;
                          }
                return true;
        }

03/16/07 23:39:54 changed by kris

  • status changed from reopened to closed.
  • resolution set to fixed.

That's what it should be ~ thanks!