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

Closed
randall77 opened this issue Jul 16, 2021 · 3 comments
Closed

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

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

Comments

@randall77
Copy link
Contributor

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

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

@randall77 randall77 added this to the Go1.18 milestone Jul 16, 2021
@randall77 randall77 added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 16, 2021
@danscales danscales self-assigned this Jul 17, 2021
@gopherbot
Copy link

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>
@randall77
Copy link
Contributor Author

@gopherbot didn't close this one either. Methinks it isn't closing issues when fixes are checked into dev.typeparams.

@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

3 participants