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

cmd/vet: unitchecker panic checking left shift with float #65939

Closed
hajimehoshi opened this issue Feb 26, 2024 · 3 comments
Closed

cmd/vet: unitchecker panic checking left shift with float #65939

hajimehoshi opened this issue Feb 26, 2024 · 3 comments
Assignees
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hajimehoshi
Copy link
Member

Go version

go1.22

Output of go env in your module/workspace:

n/a

What did you do?

Run this: https://go.dev/play/p/oVYKMHyztHy

package main

func main() {
	a := 1
	println(a << 2.0)
}

What did you see happen?

Panic:

# [play]
panic: 2 not an Int

goroutine 25 [running]:
go/constant.Int64Val({0x7ba0b8?, 0xc000111140?})
	go/constant/value.go:516 +0x109
cmd/vendor/golang.org/x/tools/go/analysis/passes/shift.checkLongShift(0xc000122b60, {0x7b83d0, 0xc000015f50}, {0x7b9548, 0xc00005f2a0}, {0x7b9998, 0xc00005f2c0})
	cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go:92 +0xbe
cmd/vendor/golang.org/x/tools/go/analysis/passes/shift.run.func2({0x7b83d0, 0xc000015f50})
	cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go:64 +0x105
cmd/vendor/golang.org/x/tools/go/ast/inspector.(*Inspector).Preorder(0xc0001820a8, {0xc000147bd0?, 0x969ae0?, 0x30?}, 0xc0000a7c10)
	cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go:82 +0x8f
cmd/vendor/golang.org/x/tools/go/analysis/passes/shift.run(0xc000122b60)
	cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go:55 +0x159
cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.run.func2.1()
	cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go:382 +0x8ce
sync.(*Once).doSlow(0x6ee9e0?, 0xc00011e480?)
	sync/once.go:74 +0xc2
sync.(*Once).Do(...)
	sync/once.go:65
cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.run.func2(0x968de0)
	cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go:333 +0x19e
cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.run.func3.1(0x0?)
	cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go:404 +0x23
created by cmd/vendor/golang.org/x/tools/go/analysis/unitchecker.run.func3 in goroutine 1
	cmd/vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker.go:403 +0x47

What did you expect to see?

4 is printed

@gopherbot gopherbot added this to the Unreleased milestone Feb 26, 2024
@seankhliao seankhliao changed the title x/playground: unexpected panic with a shift operator cmd/vet: panic checking left shift with float Feb 26, 2024
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Analysis Issues related to static analysis (vet, x/tools/go/analysis) labels Feb 26, 2024
@odeke-em odeke-em changed the title cmd/vet: panic checking left shift with float cmd/vet: unitchecker panic checking left shift with float Feb 26, 2024
@bcmills
Copy link
Contributor

bcmills commented Feb 26, 2024

(attn @timothy-king)

@timothy-king timothy-king self-assigned this Feb 26, 2024
@gopherbot
Copy link

Change https://go.dev/cl/567115 mentions this issue: go/analysis/passes/shift: support constants in float syntax

@timothy-king
Copy link
Contributor

timothy-king commented Feb 26, 2024

For future reference, the underlying issue is old and it only applies to an odd code pattern. I don't believe a back port is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants