wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.25k stars 1.21k forks source link

Bind panic #1626

Open monopolly opened 2 years ago

monopolly commented 2 years ago

Description

Sorry guys, another issue) There is an issue about a go function's bind.

Here is a bind function

func (a *App) Bool(k string, v ...bool) (res bool) {
//...something here
}

here is a simple js call - its the right call of go function

Bool('key', true)

in Go I just ignore ...bool value but wails don't: panic: reflect: cannot use []bool as type bool in Call

To Reproduce

go

func (a *App) Bool(k string, v ...bool) (res bool) {
   if v != nil{
     return true
   }
  return false
}

js

let res = await Bool('key', true)

Expected behaviour

wails have to understand that bool is valid value for a go "...bool" slice

Screenshots

panic: reflect: cannot use []bool as type bool in Call

Attempted Fixes

No response

System Details

System
------
OS:     MacOS
Version:    12.4
ID:     199506
Go Version: go1.18
Platform:   darwin
Architecture:   amd64

Wails
------
Version:    v2.0.0-beta.38

Dependency          Package Name    Status      Version
----------          ------------    ------      -------
xcode command line tools    N/A     Installed   2395
npm                 N/A     Installed   8.11.0
*upx                N/A     Available   
*nsis               N/A     Installed   v3.08

* - Optional Dependency

Diagnosis
---------
Your system is ready for Wails development!
Optional package(s) installation details: 
  - upx : Available at https://upx.github.io/

If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

leaanthony commented 2 years ago

Thanks for reporting this. Just checking... If you name the function "Zool" does it still panic?

monopolly commented 2 years ago

no no, it doest't matter whats the name of the function

if go function has a lazy slice param, wails have to understand it

leaanthony commented 2 years ago

There's a good chance we aren't handling varargs. If you get rid of the 3 dots, does it still panic?

monopolly commented 2 years ago

no if I use simple []bool all is ok, just for lazy slices.

monopolly commented 2 years ago

"lazy slices" I just call them that) ...some

leaanthony commented 2 years ago

https://wails.io/docs/guides/troubleshooting#cannot-call-backend-method-from-frontend-with-variadic-arguments

At the very least we should have a better error message

monopolly commented 2 years ago

my bet sorry)

leaanthony commented 2 years ago

I mean, we shouldn't panic, but show a better message 🤣

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.