Skip to content

Commit

Permalink
Merge pull request #1514 from xushiwei/typesutil
Browse files Browse the repository at this point in the history
typesutil: Check support conf.Error
  • Loading branch information
xushiwei committed Nov 2, 2023
2 parents f781f7b + fa02f3d commit 0216d0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3
github.com/goplus/gox v1.12.2-0.20231102132054-7ebd369dd022
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba
github.com/goplus/mod v0.11.8
github.com/qiniu/x v1.13.1
golang.org/x/tools v0.14.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3 h1:+/enB6wmQenM2Ihwv/v41lSgdTf3ARPi6A8FB1A/YH4=
github.com/goplus/c2go v0.7.17-0.20231102134817-4d12585f3af3/go.mod h1:DX0qhR2JSukHgIGMS9f6Vcu0N76LYBQy2tB+UnmIx3U=
github.com/goplus/gox v1.12.2-0.20231102132054-7ebd369dd022 h1:1g5BzuA9FfZgQwQ4XJXFsNh7KfscSIJfbUp9KkOWY80=
github.com/goplus/gox v1.12.2-0.20231102132054-7ebd369dd022/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba h1:XPnDAw65OtpBFbR2XQkFz53HXN06ibEHX5xQIDffGXs=
github.com/goplus/gox v1.12.2-0.20231102143433-424983d7a5ba/go.mod h1:MOJnwqA8/rSUkn0vsayHFK7TD/3XQrdexMTqdzR70X0=
github.com/goplus/mod v0.11.8 h1:90Kbg+MJhrdsonNGXYx3HUcW4IbBlRHYpIMssJaMMxM=
github.com/goplus/mod v0.11.8/go.mod h1:yl2QncBKTdXk+8UaNsdo4u2zSpGEJYA5JKjgD3K2h00=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down
29 changes: 29 additions & 0 deletions x/typesutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"github.com/goplus/gop/cl"
"github.com/goplus/gop/token"
"github.com/goplus/gop/x/typesutil/internal/typesutil"
"github.com/goplus/gox"
"github.com/qiniu/x/errors"
"github.com/qiniu/x/log"
)

Expand Down Expand Up @@ -147,6 +149,17 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error)
NoSkipConstant: true,
})
if err != nil {
if onErr := conf.Error; onErr != nil {
if list, ok := err.(errors.List); ok {
for _, e := range list {
if ce, ok := convErr(fset, e); ok {
onErr(ce)
}
}
} else if ce, ok := convErr(fset, err); ok {
onErr(ce)
}
}
if debugPrintErr {
log.Println("typesutil.Check err:", err)
log.SingleStack()
Expand Down Expand Up @@ -194,6 +207,22 @@ func (p *Checker) Files(goFiles []*goast.File, gopFiles []*ast.File) (err error)
return
}

func convErr(fset *token.FileSet, e error) (*types.Error, bool) {
switch v := e.(type) {
case *gox.CodeError:
return &types.Error{Fset: fset, Pos: v.Pos, Msg: v.Msg}, true
case *gox.MatchError:
pos := token.NoPos
if v.Src != nil {
pos = v.Src.Pos()
}
return &types.Error{Fset: fset, Pos: pos, Msg: v.Message("")}, true
case *gox.ImportError:
return &types.Error{Fset: fset, Pos: v.Pos, Msg: v.Err.Error()}, true
}
return nil, false
}

func scopeDelete(objMap map[types.Object]types.Object, scope *types.Scope, name string) {
if o := typesutil.ScopeDelete(scope, name); o != nil {
objMap[o] = nil
Expand Down

0 comments on commit 0216d0a

Please sign in to comment.