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/types: provide TypeAndValue constructor #27787

Closed
LMMilewski opened this issue Sep 21, 2018 · 4 comments
Closed

go/types: provide TypeAndValue constructor #27787

LMMilewski opened this issue Sep 21, 2018 · 4 comments

Comments

@LMMilewski
Copy link
Member

@LMMilewski LMMilewski commented Sep 21, 2018

Currently go/types API doesn't provide any way to create TypeAndValue object for which calling the IsVoid method would return true.

@dmitshur dmitshur changed the title go/types should allow constructing a void TypeAndValue go/types: should allow constructing a void TypeAndValue Sep 21, 2018
@griesemer griesemer changed the title go/types: should allow constructing a void TypeAndValue go/types: provide TypeAndValue constructor Sep 21, 2018
@griesemer griesemer added this to the Go1.12 milestone Sep 21, 2018
@rsc
Copy link
Contributor

@rsc rsc commented Sep 26, 2018

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 19, 2018

@alandonovan We should make a decision here.

Loading

@alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Oct 19, 2018

There are ways to create TypeAndValue instances that have IsVoid, as this program demonstrates:
https://play.golang.org/p/II4bqfWa0JR

Here are some outputs:

nil                  IsNil IsValue
append               IsBuiltin
1                    IsValue
*new(int)            Addressable Assignable IsValue
map[int]int{}[0]     Assignable HasOk IsValue
func(){}()           IsVoid
<-make(chan int)     HasOk IsValue
int                  IsType

I think you can probably adapt this program to devise a workaround for your problem. There may yet be a good justification for adding a constructor to TypeAndValue, but I don't have a good sense of how one would express the mode bits. types.Eval provides at least one sane way of setting consistent groups of mode bits for all important cases, even if it might not be very efficient.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 19, 2018

@alandonovan Thanks for this! I completely forgot about types.Eval; this is just fine to construct an occasional singleton value. There's no need for an extra constructor at this point. Closing.

Loading

@griesemer griesemer closed this Oct 19, 2018
@golang golang locked and limited conversation to collaborators Oct 19, 2019
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
6 participants