Skip to content

The definition of hashing and equality for Lists is counter-intuitive and not as useful as it could be #17963

@DartBot

Description

@DartBot

This issue was originally filed by dharcourt@chromium.org


What steps will reproduce the problem?

  1. Run the following program:

  main() {
    var a = [1, 2];
    var b = [1, 2];
    var m = {a: 42};
    print(m[a]);
    print(m[b]);
    print(a == b);
  }

What is the expected output? What do you see instead?

  • Expected: 42, 42, and true.
  • Actual: 42, null, and false.

What version of the product are you using? On what operating system?

Dart VM version: 1.2.0-dev.5.12 (Thu Feb 20 01:54:16 2014) on "macos_x64"

Please provide any additional information below.

  • The fact that Lists implement pointer hashing and pointer comparison reduces their usability. Content hashing and content comparison would provide much better semantics.
  • Obviously the lists in the example above could be made constants to solve the problem in this particular case, but this is not possible in the general case.
  • Similar improvements to equality and hashing could be made for Sets and Maps (see issue List, Set and Map should have a method to compare if elements are equal #2217), but Lists are probably the most important use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.core-nlibrary-coretype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions