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

Generates invalid code when given more than 1 statement (without -quiet). #7

Open
dmitshur opened this issue Mar 20, 2018 · 0 comments

Comments

@dmitshur
Copy link
Member

dmitshur commented Mar 20, 2018

It works okay when given a single statement and -quiet is not used:

$ goexec -n 'fmt.Println("hi")'
package main

import (
	"fmt"

	"github.com/shurcooL/go-goon"
)

func main() {
	goon.Dump(fmt.Println("hi"))
}

But it generates invalid code when given multiple statements and -quiet is not used:

$ goexec -n 's := "hi"; fmt.Println(s)'
package main

import (
	"github.com/shurcooL/go-goon"
)

func main() {
	goon.Dump(s := "hi"; fmt.Println(s))
}
imports.Process: gen.go:8:14: missing ',' in argument list

It should've been turned into:

s := "hi"; goon.Dump(fmt.Println(s))

A fix might be to parse the input, count number of statements, and add goon.Dump around the last one only.

Need to parse as Go code. Otherwise it could fail on input that contains a string with a semicolon, e.g., goexec 'fmt.Println("foo;bar")'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant