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
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@LMMilewski
Copy link
Member

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 the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 21, 2018
@griesemer griesemer added this to the Go1.12 milestone Sep 21, 2018
@rsc
Copy link
Contributor

rsc commented Sep 26, 2018

/cc @griesemer @alandonovan

@griesemer
Copy link
Contributor

@alandonovan We should make a decision here.

@alandonovan
Copy link
Contributor

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.

@griesemer
Copy link
Contributor

@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.

@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.
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants