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

proposal: spec: expand type inference for short declarations #14326

Closed
dlsniper opened this issue Feb 14, 2016 · 2 comments
Closed

proposal: spec: expand type inference for short declarations #14326

dlsniper opened this issue Feb 14, 2016 · 2 comments
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Milestone

Comments

@dlsniper
Copy link
Contributor

dlsniper commented Feb 14, 2016

Hi,

In the following code:

package main

func main() {
    x := make([]int64, 1000000)
    for i := 0; i < 1000000; i++ {
        x[i] = i
    }
}

the compiler doesn't seem to understand how to set type of i, it gives the following error: : cannot use i (type int) as type int64 in assignment.

I know one can do: x[i] = int64(i) or even better, for i := int64(0); i < 1000000; i++ (the later being a bit better for performance) but in this case I would prefer the Go compiler to optimize this out and not have me manually make the changes needed.

Thank you.

@ianlancetaylor ianlancetaylor changed the title Better type inference in for loops language: better type inference in for loops Feb 14, 2016
@ianlancetaylor ianlancetaylor added the v2 A language change or incompatible library change label Feb 14, 2016
@ianlancetaylor ianlancetaylor added this to the Proposal milestone Feb 14, 2016
@ianlancetaylor
Copy link
Contributor

That would not be a backward compatible change, so it can not happen in Go version 1.

A prerequisite for any such change in any possible Go version 2 would be to write down clear, simple rules for how the type of i is determined.

@rsc rsc changed the title language: better type inference in for loops proposal: spec: expand type inference for short declarations Jun 16, 2017
@ianlancetaylor
Copy link
Contributor

In the absence of clear, simple rules, I am going to close this.

We like type inference but it needs to be clear and straightforward. This approach requires significant analysis, and it's not always clear whether a solution is possible. This sounds more like Haskell than Go.

@golang golang locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

3 participants