mixed named and unnamed parameters in golang

I am facing an issue with my code, and it is giving me an error:

unnamed and mixed parameters

func(uc fyne.URIWriteCloser, error) { ... } 
0

2 Answers

It looks like you declared a function that has a named, and an unnamed parameter, which you cannot do.

There are two ways you can handle parameters in a func. You can either name all of the parameters, or provide no names to any of the parameters.

This is a valid func signature with both parameters named.

func(uc fyne.URIWriteCloser, err error) { // do something } 

And so is this, without naming the parameters.

func(fyne.URIWriteCloser, error) { // do something } 

If you were to name the first param, but leave the second param unnamed

func(uc fyne.URIWriteCloser, error) { // do something } 

Then you would see this error

Function has both named and unnamed parameters 

So, the problem is that the second param simply declares the param type and not the name, while the first param is defining the type and naming the param.

As specified in the specs for Function Types:

Within a list of parameters or results, the names (IdentifierList) must either all be present or all be absent.

  • If present, each name stands for one item (parameter or result) of the specified type and all non-blank names in the signature must be unique.
  • If absent, each type stands for one item of that type.

Parameter and result lists are always parenthesized except that if there is exactly one unnamed result it may be written as an unparenthesized type.

So either remove uc, or add err error.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like