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/compile: typeparams: ++ operator doesn't instantiate correctly #47258

Open
randall77 opened this issue Jul 16, 2021 · 2 comments
Open

cmd/compile: typeparams: ++ operator doesn't instantiate correctly #47258

randall77 opened this issue Jul 16, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@randall77
Copy link
Contributor

@randall77 randall77 commented Jul 16, 2021

package main

type C interface {
	int32
}

func inc[T C](x T) T {
	x++
	return x
}
func main() {
	println(inc(int32(5)))
}

$ go run -gcflags=-G=3 ~/gowork/tmp2.go
# command-line-arguments
../../../gowork/tmp2.go:8:3: invalid operation: x + 1 (mismatched types int32 and int)
../../../gowork/tmp2.go:12:13: invalid operation: x + 1 (mismatched types int32 and int)

I think the 1 introduced by ++ needs to have the type of the LHS.

Not sure why there are two errors also.

@danscales

@randall77
Copy link
Contributor Author

@randall77 randall77 commented Jul 16, 2021

x+=1 and x=x+1 both work fine.

@randall77 randall77 added this to the Go1.18 milestone Jul 16, 2021
@danscales danscales self-assigned this Jul 17, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 20, 2021

Change https://golang.org/cl/336009 mentions this issue: [dev.typeparams] cmd/compile: handle ++/-- in noder2 for expression with generic type

gopherbot pushed a commit that referenced this issue Jul 21, 2021
…h generic type

types2 will have already proved the expression's type is compatible, so
just assign the one const to have the same type as the operand.

Fixes #47258.

Change-Id: If0844e6bf6d0a5e6b11453b87df71353863ccc5d
Reviewed-on: https://go-review.googlesource.com/c/go/+/336009
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants