golang/go

x/tools/gopls: Completion of generic argument resulting in invalid casting to constraints

Opened this issue · 0 comments

gopls version

Build info
----------
golang.org/x/tools/gopls v0.20.0
    golang.org/x/tools/gopls@v0.20.0 h1:fxOYZXKl6IsOTKIh6IgjDbIDHlr5btOtOUkrGOgFDB4=
    github.com/BurntSushi/toml@v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
    github.com/fatih/camelcase@v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
    github.com/fatih/gomodifytags@v1.17.1-0.20250423142747-f3939df9aa3c h1:dDSgAjoOMp8da3egfz0t2S+t8RGOpEmEXZubcGuc0Bg=
    github.com/fatih/structtag@v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
    github.com/fsnotify/fsnotify@v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
    github.com/google/go-cmp@v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
    golang.org/x/exp/typeparams@v0.0.0-20250620022241-b7579e27df2b h1:KdrhdYPDUvJTvrDK9gdjfFd6JTk8vA1WJoldYSi0kHo=
    golang.org/x/mod@v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
    golang.org/x/sync@v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
    golang.org/x/sys@v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
    golang.org/x/telemetry@v0.0.0-20250710130107-8d8967aff50b h1:DU+gwOBXU+6bO0sEyO7o/NeMlxZxCZEvI7v+J4a1zRQ=
    golang.org/x/text@v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
    golang.org/x/tools@v0.35.1-0.20250728180453-01a3475a31bc h1:ZRKyKRJl/YEWl9ScZwd6Ua6xSt7DE6tHp1I3ucMroGM=
    golang.org/x/vuln@v1.1.4 h1:Ju8QsuyhX3Hk8ma3CesTbO8vfJD9EvUBgHvkxHBzj0I=
    honnef.co/go/tools@v0.7.0-0.dev.0.20250523013057-bbc2f4dd71ea h1:fj8r9irJSpolAGUdZBxJIRY3lLc4jH2Dt4lwnWyWwpw=
    mvdan.cc/gofumpt@v0.8.0 h1:nZUCeC2ViFaerTcYKstMmfysj6uhQrA2vJe+2vwGU6k=
    mvdan.cc/xurls/v2@v2.6.0 h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=
go: go1.25.0

go env

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/fabianr/go/bin'
GOCACHE='/Users/fabianr/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/fabianr/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/81/cvjd0t010fgbf1nc2p9xcq4w0000gn/T/go-build1529847086=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/fabianr/svn/be/trunk/gamelogic/gohome/src/elk/go.mod'
GOMODCACHE='/Users/fabianr/svn/be/trunk/gamelogic/gohome/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/fabianr/svn/be/trunk/gamelogic/gohome'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/fabianr/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Given

type C interface{ ~int }

func A[T ~int](T) int { return 0 }
func B[T C](T) int    { return 0 }
func completeMe() int { return 0 }

tried to complete the comps in

func _() int { return A(comp) }
func _() int { return B(comp) }

What did you see happen?

They got completed to

func _() int { return A(~int(completeMe())) }
func _() int { return B(C(completeMe())) }

both of which are invalid.

What did you expect to see?

func _() int { return A(completeMe()) }
func _() int { return B(completeMe()) }

Editor and settings

VSCode:

{
    "go.toolsManagement.autoUpdate": true,
    "telemetry.telemetryLevel": "off",
    "editor.autoClosingDelete": "always",
    "editor.tabSize": 3,
    "editor.unfoldOnClickAfterEndOfLine": true,
    "editor.fontSize": 10,
    "editor.unicodeHighlight.includeStrings": false,
    "indentRainbow.colors": [
        "rgba(252,255,64,0.14)",
        "rgba(74,255,64,0.14)",
        "rgba(64,228,255,0.14)",
        "rgba(144,64,255,0.14)",
        "rgba(230,64,255,0.14)",
        "rgba(255,64,64,0.14)",
        "rgba(255,173,64,0.14)"
    ],
    "go.addTags": {
        "tags": "json,action",
        "options": "json=omitempty",
        "promptForTags": false,
        "transform": "snakecase",
        "template": "",
    },
    "go.inlayHints.functionTypeParameters": true,
    "editor.minimap.showSlider": "always",
    "editor.minimap.size": "fit",
    "editor.codeActionsOnSave": {
        
    },
    "editor.guides.bracketPairs": true,
    "editor.tabCompletion": "on",
    "editor.wordWrap": "on",
    "workbench.commandPalette.experimental.suggestCommands": true,
    "workbench.editor.defaultBinaryEditor": "default",
    "workbench.editor.highlightModifiedTabs": true,
    "workbench.editor.pinnedTabsOnSeparateRow": true,
    "workbench.editor.wrapTabs": true,
    "go.editorContextMenuCommands": {
        "removeTags": true,
        "fillStruct": true,
        "testFile": true,
        "testPackage": true
    },
    "vscode-pets.throwBallWithMouse": true,
    "vscode-pets.petSize": "large",
    "go.buildTags": "dev",
    "explorer.openEditors.sortOrder": "alphabetical",
    "editor.fontFamily": "Go Mono, Menlo, Monaco, 'Courier New', monospace",
    "editor.rulers": [
        80, 100, 120
    ],
    "cmake.showOptionsMovedNotification": false,
    "editor.unicodeHighlight.ambiguousCharacters": false,
    "workbench.editor.editorActionsLocation": "titleBar",
    "window.density.editorTabHeight": "compact",
    "workbench.editor.openSideBySideDirection": "down",
    "svnBlamer.autoBlame": true,
    "workbench.colorTheme": "Shades of Purple",
    "github.copilot.enable": {
        "*": false,
        "plaintext": false,
        "markdown": false,
        "scminput": false
    },
    "go.inlayHints.constantValues": true,
}

Logs

No response