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

x/tools/go/packages: NeedSyntax without NeedFiles/NeedCompiledGoFiles produces empty slice #56677

Open
mdempsky opened this issue Nov 9, 2022 · 0 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mdempsky
Copy link
Member

mdempsky commented Nov 9, 2022

The program below prints:

runtime (LoadMode(NeedName|NeedSyntax)):
	len(Syntax) = 0
	Errors: []

runtime (LoadMode(NeedName|NeedFiles|NeedSyntax)):
	len(Syntax) = 136
	Errors: []

runtime (LoadMode(NeedName|NeedCompiledGoFiles|NeedSyntax)):
	len(Syntax) = 145
	Errors: [/home/mdempsky/wd/go/src/runtime/asm.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/asm_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/duff_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/memclr_amd64.s:7:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/memmove_amd64.s:28:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/preempt_amd64.s:3:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/rt0_linux_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/sys_linux_amd64.s:9:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/time_linux_amd64.s:7:1: illegal character U+0023 '#']

I think only the middle case is working as documented.

The last case appears to be due to #56632.

package main

import (
	"fmt"
	"log"

	"golang.org/x/tools/go/packages"
)

func main() {
	var modes = []packages.LoadMode{
		packages.NeedName | packages.NeedSyntax,
		packages.NeedName | packages.NeedFiles | packages.NeedSyntax,
		packages.NeedName | packages.NeedCompiledGoFiles | packages.NeedSyntax,
	}

	for _, mode := range modes {
		cfg := packages.Config{Mode: mode}
		pkgs, err := packages.Load(&cfg, "runtime")
		if err != nil {
			log.Fatal(err)
		}
		pkg := pkgs[0]
		fmt.Printf("%v (%v):\n\tlen(Syntax) = %v\n\tErrors: %v\n\n", pkg.PkgPath, mode, len(pkg.Syntax), pkg.Errors)
	}
}
@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 9, 2022
@mdempsky mdempsky added this to the Unreleased milestone Nov 9, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants