Skip to content
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

go/parser: builtin.make function is parsed incorrectly #20325

Closed
ingvagabund opened this issue May 11, 2017 · 4 comments
Closed

go/parser: builtin.make function is parsed incorrectly #20325

ingvagabund opened this issue May 11, 2017 · 4 comments

Comments

@ingvagabund
Copy link

@ingvagabund ingvagabund commented May 11, 2017

What version of Go are you using (go version)?

Any

What operating system and processor architecture are you using (go env)?

Any

What did you do?

Parsing src/builtin/builtin.go with go/parser package.

What did you expect to see?

Parameters of func make(Type, size IntegerType) Type are parsed as:

  • First parameter: name empty, datatype Type
  • Second parameter: name size, datatype IntegerType

What did you see instead?

Parameters of func make(Type, size IntegerType) Type are parsed as:

  • First parameter: name Type, datatype IntegerType
  • Second parameter: name size, datatype IntegerType

Notice different data type of the first parameter.

Additional data

Given the make can accept 3 arguments (given the way it is used), this does not matter. Every tool eating output of the go/parser must test the number of arguments and based on that determine what data types are/can be actually used.

If it is a bug, it can be fixed as:

func make(type Type, size IntegerType) Type

or

func make(Type, IntegerType) Type
@ingvagabund
Copy link
Author

@ingvagabund ingvagabund commented May 11, 2017

Optional, given the make accept 2-3 arguments, does it make sense to declare it as:

func make(type Type, size... IntegerType) Type

?

@cznic
Copy link
Contributor

@cznic cznic commented May 11, 2017

It is parsed correctly:

Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation.

type Type int

@ingvagabund
Copy link
Author

@ingvagabund ingvagabund commented May 12, 2017

It is parsed correctly:

I can not disagree with what it says. The thing is the way the function make is parsed. For me, it is more useful to declare the function as make(Type, IntegerType) Type. This way I can check if the first parameter is Type. If it is, I can return the first argument as the make's result type.

Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation.

type Type int
@ALTree ALTree changed the title builtin.make function is parsed incorrectly go/parser: builtin.make function is parsed incorrectly May 13, 2017
@gopherbot
Copy link

@gopherbot gopherbot commented May 13, 2017

CL https://golang.org/cl/43460 mentions this issue.

@bradfitz bradfitz added this to the Go1.9 milestone May 13, 2017
@gopherbot gopherbot closed this in 1fcd786 May 13, 2017
@golang golang locked and limited conversation to collaborators May 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.