Go version

go version go1.25rc1 linux/amd64

Output of go env in your module/workspace:

.

What did you do?

package main

import (
    "go/ast"
    "go/parser"
    "go/token"
    "go/types"
    "log"
)

func main() {
    src := `
    package p
    type I interface { M(int) string }
    `
    fset := token.NewFileSet()
    f, err := parser.ParseFile(fset, "p.go", src, 0)
    if err != nil {
        log.Fatal(err)
    }

    conf := types.Config{Importer: nil}
    info := &types.Info{Types: make(map[ast.Expr]types.TypeAndValue)}
    _, err = conf.Check("p", fset, []*ast.File{f}, info)
    if err != nil {
        log.Fatal(err)
    }

    ast.Inspect(f, func(n ast.Node) bool {
        if iface, ok := n.(*ast.InterfaceType); ok {
            for i, m := range iface.Methods.List {
                typ := info.TypeOf(m.Type)
                log.Printf("Method %d Type: %v", i, typ)
            }
        }
        return true
    })
}

What did you see happen?

non-nil method type (as Go versions before 1.25)

What did you expect to see?

nil method type.

(I'm not sure if this is a bug. Maybe something changed in Go 1.25.)

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: adonovan

I confirm that this is a go1.25 behavior change. Next step: bisect the history of go/types.

Comment From: JunyangShao

@griesemer @findleyr

Comment From: findleyr

Well, bisected to https://go.dev/cl/640596, which I suppose I might have guessed if I had first grepped the logs :) "go/types, types2: don't register interface methods in Info.Types map" - #70908

Surprised that Gaby did not succeed here. Not sure I understand this change in behavior. Reading.

Comment From: findleyr

Ok, after reading, I think we should revert https://go.dev/cl/640596.

It's perhaps unfortunate that we overloaded FieldList for interface types, but I don't think we should break the long-standing invariant that info.TypeOf(field.Type) returns the type of a field. Additionally, the CL did not update any documentation of types.Info, despite changing its behavior. The CL changing documentation (https://go.dev/cl/640776) only mentions identifiers and FuncDecl.Type.

I think both the old and new semantics are inconsistent and fiddly, but we should preserve the old fiddliness over new fiddliness :)

Comment From: findleyr

Reverting in https://go.dev/cl/683297. CC @mrkfrmn

Comment From: gopherbot

Change https://go.dev/cl/683297 mentions this issue: Revert "go/types, types2: don't register interface methods in Info.Types map"

Comment From: zigo101

So this was a changed made in Feb, for Go 1.24. Strangely this problem doesn't exist with Go toolchain 1.24.

Comment From: findleyr

@zigo101 the tree was open at that time. It is not in the 1.24 release branch.

Comment From: gopherbot

Change https://go.dev/cl/683595 mentions this issue: go/types: add test for interface method field type

Comment From: findleyr

This is now fixed in tip, and so will be in the rc2 (assuming we have one), otherwise fixed in 1.25.