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

spec: incorrect annotation to code example #48422

Closed
3bodar opened this issue Sep 16, 2021 · 4 comments
Closed

spec: incorrect annotation to code example #48422

3bodar opened this issue Sep 16, 2021 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@3bodar
Copy link

3bodar commented Sep 16, 2021

The "int" in the comment below is incorrect, should be "int32" (example from here):

var n = 1.0<<s == j            // 1.0 has type int; n == true

According to the rules

If the left operand of a non-constant shift expression is an untyped constant, it is first implicitly converted to the type it would assume if the shift expression were replaced by its left operand alone.

So the untyped constant 1.0 will be converted to the type is would assume if the declaration was var n = 1.0 == j, which is the type of j, int32.

All other annotations in that snippet are in agreement with the rules, afaict.

@ianlancetaylor
Copy link
Contributor

CC @griesemer

I think this is correct.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 16, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Sep 16, 2021
@griesemer griesemer self-assigned this Sep 16, 2021
@griesemer
Copy link
Contributor

Agreed that it should be int32. And the type checker agrees as well.

@gopherbot
Copy link

Change https://golang.org/cl/350409 mentions this issue: spec: fix incorrect type in a shift example

@gopherbot
Copy link

Change https://golang.org/cl/350410 mentions this issue: go/types, types2: add an additional shift test case

gopherbot pushed a commit that referenced this issue Sep 16, 2021
The extra test just confirms that the type-checker internally
agrees with the spec with the (otherwise invisible) type given
to an untyped constant in a specific shift expression.

For #48422.

Change-Id: I6d98045f90bd20b0cc0a96a147bec9701039cb07
Reviewed-on: https://go-review.googlesource.com/c/go/+/350410
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants