-
Notifications
You must be signed in to change notification settings - Fork 18
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
Invalid behavior in some functions with return parameters #898
Comments
The function The disassembled code is
The error is not due to the
and disassembled:
|
Another version of this issue: package main
import (
"fmt"
)
func s() []int { return []int{} }
func f() (err error) {
defer func() {
_ = recover()
_ = s()
}()
var i int
_ = 1 / i
return nil
}
func main() {
fmt.Println(f())
} Yet another version of the issue: package main
import (
"fmt"
)
func f() interface{} {
defer func() {
_ = []int{}
recover()
}()
panic(0)
}
func main() {
fmt.Println(f())
} May be the problem related to the finalizer? |
A simplified version of the issue: package main
import (
"fmt"
)
func f() []int {
defer func() {
recover()
}()
panic("")
}
func main() {
fmt.Println(f())
} |
First problemThe problem of uninitialized registers may be solved by changing Second problem (just an optimization)The code above should be executed only if the function has at least one defer statement in it; otherwise, it's useful. This information may be returned by the type checker. Third problemEven implementing the above changes, the problem continues to arise with some tests. This appears to be caused by something wrong in the emission of the statement defer; perhaps it is related to stack shift. |
The linked PR fixes the problem of registers initialization, but still remains something related to the defer statement. This code shows the invalid behaviour: package main
import (
"fmt"
)
func f() interface{} {
defer func() {
_ = []int{}
recover()
}()
panic(0)
}
func main() {
fmt.Println(f())
} It should print |
Source code
Scriggo output
gc output
The text was updated successfully, but these errors were encountered: