#2577 js: missing Uri.hash implementation

SlimerDude Sat 19 Nov 2016

A simple program that keeps calling Map.getOrAdd() until the same key is added:

@Js
class Example {
    private Uri:Str vals := [:]
	
    Bool addVal(Uri key) {
        added := false
        vals.getOrAdd(key) |->Str| { added = true; return "Val" }
        return added
    }

    Void main() {
        while (addVal(`key`)) {
            echo(vals)
        }
    }
}

Works fine in Java and only adds key the once:

C:\>fpm run afExample::Example

FPM: Running afExample::Example
===============================

[key:Val]

But enters an infinite loop in Javascript:

C:\>fpm run -js afExample::Example

FPM: Running compilerJs::Runner afExample::Example
====================================================

[key:Val]
[key:Val, key:Val]
[key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val]
[key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val, key:Val]
...

Note it works fine if you change the map to a primitive key, such as:

private Str:Str vals := [:]

andy Mon 21 Nov 2016

Are you working off tip?

SlimerDude Mon 21 Nov 2016

It was 1.0.69, but I've just compiled tip and I'm still seeing the issue when I run the example in a browser.

andy Mon 21 Nov 2016

Ticket promoted to #2577 and assigned to andy

Yeah - actually my last fix to "fix" it - actually broke it :)

Obj.hash used to return 0 - which would cause some interesting things to happen :) So I fixed that to return an increasing id by default.

But now anything that did not override hash will have some problems - in this case its Uri. Should be an easy fix - I'll look tomorrow.

andy Tue 22 Nov 2016

Ticket resolved in 1.0.70

Fixed - changeset

SlimerDude Tue 22 Nov 2016

Hi,

Ticket resolved in 1.0.70

Cool!

But now anything that does not override hash will have some problems

I had a quick look at the Javascript implementations of the other const classes in sys, and the following don't seem to have hash() implementations either:

  • Bool
  • Charset
  • Decimal
  • Enum
  • Log
  • Pod
  • Slot
  • TimeZone
  • Type

Do these need updating too?

andy Thu 24 Nov 2016

Yes most likely - let me run through them and see - thanks Steve

Login or Signup to reply.