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

missing function body - x/tools/go/ssa/interp/testdata/src/os/os.go:3:6 #40140

Closed
DIYCardSecurity opened this issue Jul 9, 2020 · 6 comments
Closed

Comments

@DIYCardSecurity
Copy link

@DIYCardSecurity DIYCardSecurity commented Jul 9, 2020

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

$ go version
go version go1.14.2 linux/amd64

Does this issue reproduce with the latest release?

Yes however it occurred in go 1.12 and so I upgraded to the latest (that's through the official openSUSE repos so perhaps not the absolute cutting edge release).

Also, it was happening on openSUSE 15.1 and I upgraded to 15.2 with no change.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/reg/.cache/go-build"
GOENV="/home/reg/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/reg/Jobs/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib64/go/1.14"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib64/go/1.14/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build995400351=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.14.2 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.14.2
uname -sr: Linux 5.3.18-lp152.20.7-default
LSB Version:	core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64:desktop-4.0-amd64:desktop-4.0-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch:graphics-4.0-amd64:graphics-4.0-noarch
Distributor ID:	openSUSE
Description:	openSUSE Leap 15.2
Release:	15.2
Codename:	n/a
/lib64/libc.so.6: GNU C Library (GNU libc) stable release version 2.26 (git 1c9a5c270d8b), by Roland McGrath et al.
gdb --version: GNU gdb (GDB; openSUSE Leap 15.2) 8.3.1

What did you do?

Added the code:

	if err := Config.validate(p); err != nil {
		os.Exit(1)
	}

and the import for the os.Exit(1) seems to have caused it since when I comment out that line it compiles just fine.

What did you expect to see?

To compile without errors, at least with only errors from my mistakes, not from calling a core function.

What did you see instead?

Compile error as follows:

/usr/lib64/go/1.14/bin/go build -o /tmp/___1go_build_main_go_debugFlags -gcflags "all=-N -l" /home/reg/Jobs/Go/src/savior/server/main.go
# golang.org/x/tools/go/ssa/interp/testdata/src/os
Jobs/Go/src/golang.org/x/tools/go/ssa/interp/testdata/src/os/os.go:3:6: missing function body
Jobs/Go/src/golang.org/x/tools/go/ssa/interp/testdata/src/os/os.go:5:6: missing function body
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 10, 2020

Can you please provide a more complete reproduce case? Where did you add if err := Config.validate(p); err != nil { ... }? What does Config refer to?

@DIYCardSecurity
Copy link
Author

@DIYCardSecurity DIYCardSecurity commented Jul 12, 2020

I'm not sure how much I'll need to give before you have enough but I guess we'll work our way through it.

This is the entire function it is in:

// ConfigInit loads configuration options from JSON file
func ConfigInit() {
	p := path.Join(config.Env.Paths.Config, `core.json`)
	if err := Config.loadConfigFile(p); err != nil {
		logger.Critical(`Could not load configuration file "` + p + `"`)
	}
	Config.setSpecialValueTypes()
	if err := Config.validate(p); err != nil {
		// os.Exit(1)
	}
	// v := validator.New()
	// err := v.Struct(Config)
	// logger.Error(err)
	// Config.validate(p)
}

Because ConfigInit() is stored in a variable in a struct like:

type ModuleInfo struct {
	Initializer func()
	Installer   func()
	Module      string // Name of the module. No need to hard code, will be set during initialization.
	Package     string // Package
	Updater     func()
	Weight      int // Weight for the Module Initialization. Default: 0
}

It will eventually be called with a line like:

m.Initializer()

Config.validate(p) calls the function:

func (c *Configuration) validate(p string) error {
	return c.Core.validate(p)
}

which calls:

func (core *CoreConfig) validate(p string) error {
	var err error
	errs := 0
	ancestry := `core`

	core.Cron.validate(core, ancestry, &errs)
	core.Locale.validate(core, ancestry, &errs)
	core.Server.validate(core, ancestry, &errs)
	core.Database.validate(core, ancestry, &errs)

	if errs > 0 {
		err = errors.New(`Validation errors occurred on the config file: ` + p)
	}

	return err
}

and the structs they are referring to look like:

type Configuration struct {
	Core CoreConfig
}

type CoreConfig struct {
	Cron     CronConfig `validate:"min=5m,max=1h"`
	Locale   LocaleConfig
	Server   ServerConfig
	Database DatabaseConfig
}
@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 12, 2020

I would help if you provided a higher level overview of the problem, not specifics of your codebase. Can you please answer these questions:

  1. Is there a snippet to run or a list of instructions we can follow to reproduce the problem?

  2. Does the problem still happen if you remove the -gcflags "all=-N -l" flag, or does it only happen when that's used?

  3. Is your code importing the golang.org/x/tools/go/ssa/interp/testdata/src/os package? If not, do you know where it's coming from?

Thanks.

@DIYCardSecurity
Copy link
Author

@DIYCardSecurity DIYCardSecurity commented Jul 13, 2020

Is there a snippet to run or a list of instructions we can follow to reproduce the problem?

I know how valuable this is but all as I could do is write a snippet, put it in playground and see if it errors, and I tried that and it doesn't.

Part of the problem here is that I am relatively new to go, I have been learning it mostly through my IDE (GoLand) which I have also been learning as I have not used JetBrains products before so I'm coming from a double learning curve and because I have been working mostly through my IDE I am not yet intimately knowledgeable about the ins and outs of the toolchain.

Does the problem still happen if you remove the -gcflags "all=-N -l" flag, or does it only happen when that's used?

Is your code importing the golang.org/x/tools/go/ssa/interp/testdata/src/os package? If not, do you know where it's coming from?

I think I can answer both questions above with one answer which is, I'm actively working on that bit of code so I just uncommented os.Exit(1) to test it to answer your 2nd question but this time it compiled without error. After 3 days or so of changes I have no idea what caused it nor why it went away. However, I did see the same error at another point in my code in another module a couple of weeks earlier so it wouldn't surprise me if it comes back. So, there is something rather subtle I suspect, or, I'm just doing something in my IDE that is causing something that shouldn't happen and I just don't know enough to even begin to dissect it.

So perhaps some help from you might help me help you in that can you tell me whether golang.org/x/tools/go/ssa/interp/testdata/src/os is standard and should be imported when using os? I just assumed it was as it looks like it without looking too deeply.

Is there something I can do to give you more information other than create a general snippet of code? because I don't think that's going be possible in this case with the way it comes and goes and seems to need some subtle combination of stuff.

Is there a way I can get go to clear out any unnecessary imported code as perhaps some code is just being left around when it shouldn't be and some clean up would fix it. I did run go clean by the way to try and fix it.

Is there some debug version of the compiler I could run for you to precisely identify the problem?

I wish I was already a go expert but I really am at the learning stages right now so if you could give me some guidance I will do what i can.

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jul 13, 2020

So perhaps some help from you might help me help you in that can you tell me whether golang.org/x/tools/go/ssa/interp/testdata/src/os is standard and should be imported when using os?

No, it is a test fixture. There should be no reason for code to import this package.

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Jul 13, 2020

Thanks for clarifying, that's very helpful. In the original issue report, I didn't realize you were using an IDE and could not understand where the error was coming from.

I wish I was already a go expert but I really am at the learning stages right now so if you could give me some guidance I will do what i can.

Thanks a lot for wanting to contribute. Based on what you described, there's a good chance this issue is related to something the IDE was doing. We can't really make progress here without being able to reproduce the problem, and you mentioned it no longer happens.

I'll close this now because there's nothing action to do on the Go project side at this time, but if this happens again, I suggest reporting this as a bug to the IDE and letting them investigate it on their end first. Additionally, see https://golang.org/wiki/Questions for where to ask questions and get general help.

If you get to a point where it's possible to narrow down the issue to something in the Go project, please don't hesitate to open a new issue or leave a comment here if this occurs again. Thanks.

@dmitshur dmitshur closed this Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.