Thanks to visit codestin.com
Credit goes to github.com

Skip to content

reflect.DeepEqual error for empty slice and variadic #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
visualfc opened this issue Sep 12, 2022 · 1 comment · Fixed by #1150
Closed

reflect.DeepEqual error for empty slice and variadic #1147

visualfc opened this issue Sep 12, 2022 · 1 comment · Fixed by #1150

Comments

@visualfc
Copy link
Contributor

visualfc commented Sep 12, 2022

demo

package main

import (
	"reflect"
)

func test1(v ...string) {
	var names []string
	ret := reflect.DeepEqual(names, v)
	println(ret)
}

func test2(opt int, v ...string) {
	var names []string
	ret := reflect.DeepEqual(names, v)
	println(ret)
}

func main() {
	test1()
	test2(100)
}

gopherjs run main.go

output error

true
false
@nevkontakte
Copy link
Member

Thanks for the report.

Looking at the generated code, for some reason the compiler initializes the variadic argument differently depending on whether it's the only argument or not:

$r = test1(sliceType.nil); /* */ $s = 1; case 1: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }
$r = test2(100, new sliceType([])); /* */ $s = 2; case 2: if($c) { $c = false; $r = $r.$blk(); } if ($r && $r.$blk !== undefined) { break s; }

According to the Go spec, this is a bug:

If f is invoked with no actual arguments for p, the value passed to p is nil.

nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Sep 18, 2022
Previously we would pass an empty slice, which is against the Go spec:

> If f is invoked with no actual arguments for p, the value passed to p
> is nil.

Source: https://go.dev/ref/spec#Passing_arguments_to_..._parameters

Fixes gopherjs#1147
nevkontakte added a commit to nevkontakte/gopherjs that referenced this issue Sep 18, 2022
Previously we would pass an empty slice, which is against the Go spec:

> If f is invoked with no actual arguments for p, the value passed to p
> is nil.

Source: https://go.dev/ref/spec#Passing_arguments_to_..._parameters

Fixes gopherjs#1147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants