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

go/types: missing Info.Types entry for variadic parameter *ast.Ellipsis #28277

Closed
alandonovan opened this issue Oct 19, 2018 · 3 comments
Closed

Comments

@alandonovan
Copy link
Contributor

Type-checking this program:

package p
func f(...int)

causes no type to be recorded for ...int. It should be []int.

Repro:
https://play.golang.org/p/Eki5lGS2RdF

	fset := token.NewFileSet()
	const src = `package p; func f(...int)`
	f, err := parser.ParseFile(fset, "a.go", src, 0)
	if err != nil {
		log.Fatal(err)
	}
	info := &types.Info{
		Types: make(map[ast.Expr]types.TypeAndValue),
	}

	if _, err = new(types.Config).Check("p", fset, []*ast.File{f}, info); err != nil {
		log.Fatal(err)
	}
	ellipsis := f.Decls[0].(*ast.FuncDecl).Type.Params.List[0].Type.(*ast.Ellipsis)
	_, ok := info.Types[ellipsis]
	fmt.Println(ok) // false
}
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/143298 mentions this issue: go/analysis/passes/asmdecl: fix a latent crash

@griesemer
Copy link
Contributor

It records a type for int in ...int: https://play.golang.org/p/M-5YH1mkrZM

But fair enough, it probably should also record one for ...int.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/143317 mentions this issue: go/types: collect type info for type ...T in variadic functions

gopherbot pushed a commit to golang/tools that referenced this issue Oct 19, 2018
Due to a bug in go/types, a function f(...T) has no type
recorded for the parameter type expression ...T, and apparently
this has never occcured in a file checked by asmdecl before.

The addParams function should really be simplified to use types.Signature.

Updates golang/go#28277

Change-Id: I5b73535a7739b6771ffef1c0a7568f5161d564d5
Reviewed-on: https://go-review.googlesource.com/c/143298
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Oct 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants