Comments (12)
Thanks for the report! Surprisingly, it looks like you found a bug in golang.org/x/tools/go/loader
:
Minimal loader program loader.go:
package main
import (
"fmt"
"golang.org/x/tools/go/loader"
)
func main() {
var conf loader.Config
conf.CreateFromFilenames("main", "small.go")
_, err := conf.Load()
fmt.Println(err)
}
results on your minimal test case small.go
$ go run loader.go
small.go:7:6: touchedInClosure declared but not used
couldn't load packages due to errors: main
I'll see if I can find out what's going on and get this fixed upstream.
from godebug.
This isn't a bug. Using a variable isn't just writing to it but reading it and because the variable is never used inside it's scope, it complains about it.
from godebug.
@omeid is right. It's unfortunate that godebug does not accept a program that the go tool does, though.
I was curious what the spec had to say about this. I found this:
Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used.
So the spec leaves this open, and both the go tool and the loader library are in compliance. The latter is just more strict.
from godebug.
Early versions of godebug used golang.org/x/tools/go/types
for type checking. That library does not object to small.go:
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/tools/go/types"
)
func main() {
var fs token.FileSet
f, err := parser.ParseFile(&fs, "small.go", nil, 0)
if err != nil {
fmt.Println("error in parsing: ", err)
return
}
_, err = types.Check("main", &fs, []*ast.File{f})
fmt.Println(err)
}
Running it:
$ go run parser.go
<nil>
The loader library provides a lot that the types library does not, so it might not be worth the effort to switch to it. But it would make godebug behave more like go for this case.
from godebug.
Please don't downgrade.
c2go has been written against an older version of Go and should be ported to the latest if they want to use godebug, not the other way around.
from godebug.
c2go isn't outdated. It runs on tip (or, at least, my copy of tip from last week):
~/src/github.com/glycerine/c2go$ go version
go version devel +180fbb1 Fri Mar 27 00:30:14 2015 +0000 linux/amd64
~/src/github.com/glycerine/c2go$ go run *.go
usage: c2go [options] *.c
-I string
include directory
-c string
config file
-dst string
GOPATH root of destination (default "/tmp/c2go")
exit status 2
The surprising behavior is that godebug
's type checker behaves differently from go
's type checker, even though both are compliant with the language spec.
from godebug.
@glycerine I tried just deleting that variable from the code and godebug run
worked fine:
$ godebug run *.go
usage: c2go [options] *.c
-I="": include directory
-c="": config file
-dst="/tmp/c2go": GOPATH root of destination
from godebug.
Oops, I messed up my test with golang.org/x/tools/go/types
. I had edited small.go before I ran the test. Running again with the original file, it gives the same error as the loader library:
$ go run parser.go
small.go:7:6: touchedInClosure declared but not used
I'm going to call this one wontfix
. Sorry, @glycerine! If you want to debug that library, just delete that variable.
from godebug.
Arg. Agree we can't fix this locally, but I am still inclined to think we
should upstream this as an issue so that "go run" and the types library are
consistent.
On Sun, Apr 5, 2015 at 9:58 PM, Jeremy Schlatter [email protected]
wrote:
—
Reply to this email directly or view it on GitHub
#14 (comment).
Best regards,
Jason
from godebug.
err, I misread -- It's the "golang.org/x/tools/go/loader" library that
differs in strictness, yes?
On Mon, Apr 6, 2015 at 7:55 AM, Jason E. Aten [email protected] wrote:
Arg. Agree we can't fix this locally, but I am still inclined to think we
should upstream this as an issue so that "go run" and the types library are
consistent.On Sun, Apr 5, 2015 at 9:58 PM, Jeremy Schlatter <[email protected]
wrote:
—
Reply to this email directly or view it on GitHub
#14 (comment).Best regards,
Jason
from godebug.
opened golang/go#10356 to track upstream
from godebug.
go/loader and go/types behave the same way, and both are different from gc. I thought differently earlier in the ticket, but I was mistaken.
from godebug.
Related Issues (20)
- Does it work on Windows? HOT 4
- Feature Request: Auto-print after breakpoint HOT 1
- Windows binaries lack .exe extension
- Functions defined as part of an array or slice literal are not instrumented
- Can't convert variables to other types to inspect with print command HOT 2
- --ldflags is not supported HOT 1
- godebug not found HOT 2
- Auto instrument packages with breakpoints
- Can't get `godebug test` to work on Terraform codebase
- Doesn't handle bad recover usage
- Godebug does not work with vendoring HOT 5
- syntax highlighting
- search package only in base gopath HOT 3
- Website not updated
- cannot find package "golang_org/x/net/route" HOT 1
- godebug does not work with code that imports net/http (since go 1.6) HOT 10
- godebug fails after addition of net/http package HOT 1
- cgdb like TUI for godebug.
- So what's the deal? HOT 3
- question a bout debuger HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godebug.