Skip to content

Commit

Permalink
Merge pull request #314 from goplus/main
Browse files Browse the repository at this point in the history
v1.13.1
  • Loading branch information
xushiwei authored Nov 25, 2023
2 parents 19b9702 + 0aae3d8 commit 719ee16
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 64 deletions.
20 changes: 18 additions & 2 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go/types"
"log"
"math/big"
"strings"
"testing"
"unsafe"

Expand Down Expand Up @@ -587,7 +588,7 @@ func TestStructFieldType(t *testing.T) {
}
struc := types.NewStruct(flds, nil)
cb.Val(nil)
if !cb.fieldRef(nil, struc, "val") {
if !cb.fieldRef(nil, struc, "val", nil) {
t.Fatal("structFieldType failed")
}
}
Expand All @@ -605,7 +606,7 @@ func TestStructFieldType2(t *testing.T) {
}
struc := types.NewStruct(flds, nil)
cb.Val(nil)
if !cb.fieldRef(nil, struc, "val") {
if !cb.fieldRef(nil, struc, "val", nil) {
t.Fatal("structFieldType failed")
}
}
Expand Down Expand Up @@ -1049,6 +1050,21 @@ func TestImportPkg(t *testing.T) {
}
}

func TestImportError(t *testing.T) {
defer func() {
err := recover()
if err == nil {
t.Fatal("no error")
}
if !strings.HasPrefix(err.(error).Error(), "package bad is not in") {
t.Fatal("bad import error", err)
}
}()
pkg := NewPackage("github.com/goplus/gox", "gox", gblConf)
f := &File{importPkgs: make(map[string]*PkgRef)}
f.importPkg(pkg, "bad", nil)
}

func TestForRangeStmtPanic(t *testing.T) {
defer func() {
if e := recover(); e != nil {
Expand Down
2 changes: 1 addition & 1 deletion c.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (p *BitFields) FieldRef(cb *CodeBuilder, t *types.Named, name string, src a
if v.Name == name {
stk := cb.stk
o := t.Underlying().(*types.Struct)
if cb.fieldRef(stk.Get(-1).Val, o, v.FldName) {
if cb.fieldRef(stk.Get(-1).Val, o, v.FldName, src) {
fld := stk.Get(-1)
tfld := fld.Type.(*refType).typ.(*types.Basic)
stk.Ret(1, &internal.Elem{
Expand Down
15 changes: 9 additions & 6 deletions codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,28 +1427,31 @@ func (p *CodeBuilder) MemberRef(name string, src ...ast.Node) *CodeBuilder {
return p
}

func (p *CodeBuilder) refMember(typ types.Type, name string, argVal ast.Expr) MemberKind {
func (p *CodeBuilder) refMember(typ types.Type, name string, argVal ast.Expr, src ast.Node) MemberKind {
switch o := indirect(typ).(type) {
case *types.Named:
if struc, ok := p.getUnderlying(o).(*types.Struct); ok {
name = p.getFieldName(o, name)
if p.fieldRef(argVal, struc, name) {
if p.fieldRef(argVal, struc, name, src) {
return MemberField
}
return p.refVField(o, name, argVal)
}
case *types.Struct:
if p.fieldRef(argVal, o, name) {
if p.fieldRef(argVal, o, name, src) {
return MemberField
}
}
return MemberInvalid
}

func (p *CodeBuilder) fieldRef(x ast.Expr, o *types.Struct, name string) bool {
func (p *CodeBuilder) fieldRef(x ast.Expr, o *types.Struct, name string, src ast.Node) bool {
for i, n := 0, o.NumFields(); i < n; i++ {
fld := o.Field(i)
if fld.Name() == name {
if p.rec != nil {
p.rec.Member(src, fld)
}
p.stk.Ret(1, &internal.Elem{
Val: &ast.SelectorExpr{X: x, Sel: ident(name)},
Type: &refType{typ: fld.Type()},
Expand All @@ -1462,7 +1465,7 @@ func (p *CodeBuilder) fieldRef(x ast.Expr, o *types.Struct, name string) bool {
if t, ok := fldt.(*types.Named); ok {
u := p.getUnderlying(t)
if struc, ok := u.(*types.Struct); ok {
if p.fieldRef(x, struc, name) || p.refVField(t, name, nil) != MemberInvalid {
if p.fieldRef(x, struc, name, src) || p.refVField(t, name, nil) != MemberInvalid {
return true
}
}
Expand Down Expand Up @@ -1514,7 +1517,7 @@ func (p *CodeBuilder) Member(name string, flag MemberFlag, src ...ast.Node) (kin
}
at := arg.Type
if flag == MemberFlagRef {
kind = p.refMember(at, name, arg.Val)
kind = p.refMember(at, name, arg.Val, srcExpr)
} else {
t, isType := at.(*TypeType)
if isType {
Expand Down
1 change: 0 additions & 1 deletion error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1381,5 +1381,4 @@ type M struct {
MemberVal("x", source("m.x", 3, 10)).Call(1).EndStmt().
End()
})

}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/goplus/gox

go 1.18

require golang.org/x/tools v0.14.0
require golang.org/x/tools v0.15.0

retract (
v1.12.7
Expand Down
58 changes: 5 additions & 53 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,53 +1,5 @@
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk=
3 changes: 3 additions & 0 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ func (p *ImportError) Unwrap() error {
}

func (p *ImportError) Error() string {
if p.Pos == token.NoPos {
return fmt.Sprintf("%v", p.Err)
}
pos := p.Fset.Position(p.Pos)
return fmt.Sprintf("%v: %v", pos, p.Err)
}
Expand Down

0 comments on commit 719ee16

Please sign in to comment.