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, types2: constant with inferred type constrained by constraints.Integer not allowed as shifted operand #49705

fzipp opened this issue Nov 21, 2021 · 1 comment


Copy link

fzipp commented Nov 21, 2021

What version of Go are you using (go version)?

$ go version
go version devel go1.18-91abe4be0e Sat Nov 20 08:47:36 2021 +0000 darwin/arm64

What did you do?

package main

import "constraints"

func shl[I constraints.Integer](n I) I {
	return 1 << n

func main() {}

What did you expect to see?

Successful compilation, because the non-generic function would compile for all types covered by constraints.Integer.

What did you see instead?

./prog.go:6:9: invalid operation: shifted operand 1 (type I) must be integer

The generic function compiles with an explicit type conversion:

func shl[I constraints.Integer](n I) I {
	return I(1) << n
Copy link

Change mentions this issue: cmd/compile/internal/types2: use allInteger to check type for shifted operand

@golang golang locked and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

2 participants