gopherjs icon indicating copy to clipboard operation
gopherjs copied to clipboard

reflect breaks pointer comparison

Open luna-duclos opened this issue 9 years ago • 5 comments

The following sample using reflect to compare pointers works in gc, but it fails when using gopherJS.

http://play.golang.org/p/33bND01kB0

luna-duclos avatar Dec 20 '15 18:12 luna-duclos

Thx for the bug report. I've neglected Addr a bit, since it's mostly used in unsafe contexts that are not supported by GopherJS. But I think your use case is valid and there should be a way to support it.

neelance avatar Dec 20 '15 20:12 neelance

Here is a second test case that might need work: http://play.golang.org/p/8tDGNnhoXm I suspect the fix will be the same for both issues, but I'm posting this just in case

luna-duclos avatar Dec 20 '15 21:12 luna-duclos

Hmm, in my first message I confused Addr with Pointer. Only Pointer is related to unsafe.

According to the documentation of reflect.Value, your first example is not guaranteed to work. It says:

"Using == on two Values does not compare the underlying values they represent, but rather the contents of the Value structs. To compare two Values, compare the results of the Interface method."

Your second example however seems correct. I'm looking into fixing it.

neelance avatar Jan 15 '16 17:01 neelance

This seems to be working now? At least the two playground links both return 'true' for me (which I think is expected?). Should this issue be closed?

flimzy avatar Apr 29 '17 11:04 flimzy

Both programs return true for me using gc, and false using GopherJS, so this issue is still unresolved.

@flimzy The playground links are at play.golang.org. Did you try gopherjs.org/playground?

https://play.golang.org/p/33bND01kB0 - true http://play.golang.org/p/8tDGNnhoXm - true

https://gopherjs.github.io/playground/#/33bND01kB0 - false https://gopherjs.github.io/playground/#/8tDGNnhoXm - false

dmitshur avatar Apr 29 '17 19:04 dmitshur