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: incorrectly errors when importing parameterized function in a test #47915

Closed
jakecoffman opened this issue Aug 23, 2021 · 2 comments
Closed
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@jakecoffman
Copy link

jakecoffman commented Aug 23, 2021

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

$ gotip version
go version devel go1.18-4fbb5c8 Mon Aug 23 13:09:18 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

No, using generics on gotip.

What operating system and processor architecture are you using (go env)?

go env Output
$ gotip env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jake/Library/Caches/go-build"
GOENV="/Users/jake/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jake/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jake/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/jake/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jake/sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-4fbb5c8 Mon Aug 23 13:09:18 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jake/personal/generics/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/25/cxtbvqr178x9rfg976_gqmxr0000gp/T/go-build766177970=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I created a repo here: https://github.com/jakecoffman/generics

Create a package math with min.go as follows:

package math

type comparable interface {
	~int
}

func Min[T comparable](a ...T) T {
	m := a[0]
	for _, v := range a {
		if m > v {
			m = v
		}
	}
	return m
}

Outside of package math create a test that imports the parameterized Min:

package main

import (
	"github.com/jakecoffman/generics/math"
	"testing"
)

func TestMath(t *testing.T) {
	a, b := 1, 2
	if math.Min(a, b) != 1 {
		t.Error(math.Min(a, b))
	}
}

Then run gotip test ./....

What did you expect to see?

A passing test

What did you see instead?

vet: ./main.go:5:2: could not import github.com/jakecoffman/generics/math (cannot import "github.com/jakecoffman/generics/math" (unexpected parameterized function/method), possibly version skew - reinstall package)

It works outside of a test, or in a test in the same module as the definition of the parameterized function.

@toothrot toothrot changed the title vet error when importing parameterized function in a test cmd/vet: incorrectly errors when importing parameterized function in a test Aug 24, 2021
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 24, 2021
@toothrot toothrot added this to the Backlog milestone Aug 24, 2021
@timothy-king timothy-king added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Aug 24, 2021
@timothy-king timothy-king self-assigned this Aug 30, 2021
@timothy-king
Copy link
Contributor

The example reproduces. I am seeing the same failure on gotip test ./... from within generics/ after cloning https://github.com/jakecoffman/generics @ 9eb67dd.

$ gotip version
go version devel go1.18-144e0b1f6e2 Tue Aug 31 17:35:15 2021 +0000 linux/amd64

Observations:

  • $ gotip test ./math passes.
  • $ gotip test . has the same problem.
  • $ gotip run main.go runs and prints "OK!".
  • $ gotip vet ./math passes.
  • $ gotip vet . has the same problem.

Replacing min.go with a version without generics will pass gotip test ./.... Content:

func Min(a ...int) int {
	m := a[0]
	for _, v := range a {
		if m > v {
			m = v
		}
	}
	return m
}

So it looks like this is specific to generics and blocks the test from passing.

@timothy-king timothy-king added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 31, 2021
@timothy-king timothy-king modified the milestones: Backlog, Go1.18 Aug 31, 2021
@timothy-king
Copy link
Contributor

Looks like this is a duplicate of #48101

@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
Analysis Issues related to static analysis (vet, x/tools/go/analysis) FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants