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

fix: assert switch type from valueT in struct case #747

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions _test/type25.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"errors"
"sync/atomic"
)

type wrappedError struct {
wrapped error
}

func (e wrappedError) Error() string {
return "some outer error"
}

func (e wrappedError) Unwrap() error {
return e.wrapped
}

var err atomic.Value

func getWrapped() *wrappedError {
if v := err.Load(); v != nil {
err := v.(wrappedError)
if err.wrapped != nil {
return &err
}
}
return nil
}

func main() {
err.Store(wrappedError{wrapped: errors.New("test")})

e := getWrapped()
if e != nil {
println(e.Error())
println(e.wrapped.Error())
}
}

// Output:
// some outer error
// test
44 changes: 44 additions & 0 deletions _test/type26.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"errors"
"sync/atomic"
)

type wrappedError struct {
wrapped error
}

func (e *wrappedError) Error() string {
return "some outer error"
}

func (e *wrappedError) Unwrap() error {
return e.wrapped
}

var err atomic.Value

func getWrapped() *wrappedError {
if v := err.Load(); v != nil {
err := v.(*wrappedError)
if err.wrapped != nil {
return err
}
}
return nil
}

func main() {
err.Store(&wrappedError{wrapped: errors.New("test")})

e := getWrapped()
if e != nil {
println(e.Error())
println(e.wrapped.Error())
}
}

// Output:
// some outer error
// test
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ func (interp *Interpreter) cfg(root *node, pkgID string) ([]*node, error) {
}
}
if n.anc.action != aAssignX {
if n.child[0].typ.cat == valueT {
if n.child[0].typ.cat == valueT && !isStruct(n.child[1].typ) {
// Avoid special wrapping of interfaces and func types.
n.typ = &itype{cat: valueT, rtype: n.child[1].typ.TypeOf()}
} else {
Expand Down