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

Different compilation behaviour from native go #136

Open
flamelx opened this issue Aug 26, 2022 · 2 comments
Open

Different compilation behaviour from native go #136

flamelx opened this issue Aug 26, 2022 · 2 comments
Assignees

Comments

@flamelx
Copy link

flamelx commented Aug 26, 2022

package main

import (
	"fmt"
	"github.com/cosmos72/gomacro/fast"
)

func main() {
	// case1() // as expected
	// case2() // panic: expression returns 1 value, expecting 2: "1"
	case3() // Different compilation behaviour from native go. Why did the compilation not fail?
}

func case1() {
	interp := fast.New()
	script := `func Execute()(string,error){
			return "1",nil
		}`
	interp.Eval(script)

	vs, _ := interp.Eval("Execute()")
	fmt.Println(vs[0].Interface()) // "1"
	fmt.Println(vs[1].Interface()) // nil
}

func case2() {
	interp := fast.New()
	script := `func Execute()(string,error){
			return "1"
		}`
	interp.Eval(script)

	vs, _ := interp.Eval("Execute()")
	fmt.Println(vs[0].Interface())
	fmt.Println(vs[1].Interface())
}

func case3() {
	interp := fast.New()
	script := `func Execute()(string,error){

	}`
	interp.Eval(script)

	vs, _ := interp.Eval("Execute()")
	fmt.Println(vs[0].Interface()) // ""
	fmt.Println(vs[1].Interface()) // nil
}

Is this as expected?

@cosmos72
Copy link
Owner

Gomacro does not currently report errors for missing return statements.
So in a sense, yes, this is expected.

Although I am not sure whether it's worth having such a difference from Go toolchain.

@cosmos72 cosmos72 self-assigned this Oct 20, 2022
@flamelx
Copy link
Author

flamelx commented Nov 1, 2022

Gomacro does not currently report errors for missing return statements. So in a sense, yes, this is expected.

Although I am not sure whether it's worth having such a difference from Go toolchain.

Thanks, I see.

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

2 participants