Skip to content

Commit

Permalink
Merge pull request #329 from goplus/main
Browse files Browse the repository at this point in the history
v1.13.2
  • Loading branch information
xushiwei authored Jan 7, 2024
2 parents 719ee16 + a6c41ff commit ab3a59e
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 253 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

version: 2
updates:
- package-ecosystem: github-actions
directory: /
labels:
- dependabot
- actions
schedule:
interval: daily

- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-11]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand Down
9 changes: 9 additions & 0 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ retry:
if ret.CVal == nil && isUntyped(pkg, ret.Type) {
ret.CVal = builtinCall(fn, args)
}
if pkg.cb.rec != nil {
pkg.cb.rec.Call(fn.Src, o)
}
return
}
restoreArgs(args, backup)
Expand All @@ -636,6 +639,9 @@ retry:
}
if ret, err = matchFuncCall(pkg, &mfn, args, flags); err == nil {
fn.Val, fn.Type = mfn.Val, mfn.Type
if pkg.cb.rec != nil {
pkg.cb.rec.Call(fn.Src, o)
}
return
}
restoreArgs(args, backup)
Expand All @@ -658,6 +664,9 @@ retry:
targs[j+1] = arg
}
if ret, err = matchFuncCall(pkg, tfn, targs, flags); err == nil {
if pkg.cb.rec != nil {
pkg.cb.rec.Call(fn.Src, ft.Func)
}
return
}
if isPointer(targ0.Type) {
Expand Down
114 changes: 3 additions & 111 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ func typString(pkg *Package, t types.Type) string {
func TestMethodAutoProperty(t *testing.T) {
typs := []types.Type{
tyInt,
sigFuncEx(nil, &TyOverloadFunc{}),
sigFuncEx(nil, &TyTemplateRecvMethod{types.NewParam(0, nil, "", tyInt)}),
sigFuncEx(nil, nil, &TyOverloadFunc{}),
sigFuncEx(nil, nil, &TyTemplateRecvMethod{types.NewParam(0, nil, "", tyInt)}),
}
for _, typ := range typs {
if methodHasAutoProperty(typ, 0) {
Expand All @@ -512,7 +512,7 @@ func TestMethodAutoProperty(t *testing.T) {
}

func TestIsType(t *testing.T) {
if isType(sigFuncEx(nil, &TyOverloadFunc{})) {
if isType(sigFuncEx(nil, nil, &TyOverloadFunc{})) {
t.Fatal("TestIsType: isType(TyOverloadFunc)")
}
}
Expand Down Expand Up @@ -876,114 +876,6 @@ func TestIsUnbound(t *testing.T) {
}
}

func TestCheckSignature(t *testing.T) {
denoteRecv(&ast.SelectorExpr{Sel: ident("x")})
if CheckSignature(nil, 0, 0) != nil {
t.Fatal("TestCheckSignature failed: CheckSignature(nil) != nil")
}
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
if CheckSignature(sig, 0, 0) != sig {
t.Fatal("TestCheckSignature failed: CheckSignature(sig) != sig")
}
pkg := types.NewPackage("", "foo")
arg := types.NewParam(token.NoPos, pkg, "", sig)
sig2 := types.NewSignatureType(nil, nil, nil, types.NewTuple(arg, arg), nil, false)
o := types.NewFunc(token.NoPos, pkg, "bar", sig2)
if CheckSignature(sigFuncEx(pkg, &TyTemplateRecvMethod{Func: o}), 0, 0) == nil {
t.Fatal("TestCheckSignature failed: TemplateRecvMethod CheckSignature == nil")
}

of := NewOverloadFunc(token.NoPos, pkg, "bar", o)
if CheckSignature(of.Type(), 0, 0) == nil {
t.Fatal("TestCheckSignature failed: OverloadFunc CheckSignature == nil")
}
if HasAutoProperty(of.Type()) {
t.Fatal("func bar has autoprop?")
}

if CheckSignature(sigFuncEx(pkg, &TyTemplateRecvMethod{Func: of}), 0, 0) == nil {
t.Fatal("TestCheckSignature failed: TemplateRecvMethod OverloadFunc CheckSignature == nil")
}

o2 := types.NewFunc(token.NoPos, pkg, "bar2", sig)
of2 := NewOverloadFunc(token.NoPos, pkg, "bar3", o2)
if !HasAutoProperty(of2.Type()) {
t.Fatal("func bar3 has autoprop?")
}

typ := types.NewNamed(types.NewTypeName(token.NoPos, pkg, "t", nil), types.Typ[types.Int], nil)
om := NewOverloadMethod(typ, token.NoPos, pkg, "bar", o)
if CheckSignature(om.Type(), 0, 1) != nil {
t.Fatal("TestCheckSignature failed: OverloadMethod CheckSignature != nil")
}
}

func TestCheckSignatures(t *testing.T) {
denoteRecv(&ast.SelectorExpr{Sel: ident("x")})
if CheckSignatures(nil, 0, 0) != nil {
t.Fatal("TestCheckSignatures failed: CheckSignatures(nil) != nil")
}
sig := types.NewSignatureType(nil, nil, nil, nil, nil, false)
if v := CheckSignatures(sig, 0, 0); len(v) != 1 || v[0] != sig {
t.Fatal("TestCheckSignatures failed: CheckSignatures(sig)[0] != sig")
}
pkg := types.NewPackage("", "foo")
arg := types.NewParam(token.NoPos, pkg, "", sig)
sig2 := types.NewSignatureType(nil, nil, nil, types.NewTuple(arg, arg), nil, false)
o := types.NewFunc(token.NoPos, pkg, "bar", sig2)
if CheckSignatures(sigFuncEx(pkg, &TyTemplateRecvMethod{Func: o}), 0, 0) == nil {
t.Fatal("TestCheckSignatures failed: TemplateRecvMethod CheckSignatures == nil")
}
sig3 := types.NewSignatureType(nil, nil, nil, types.NewTuple(arg, arg, arg), nil, false)
o2 := types.NewFunc(token.NoPos, pkg, "bar", sig3)
of := NewOverloadFunc(token.NoPos, pkg, "bar", o, o2)
if v := CheckSignatures(of.Type(), 0, 0); len(v) != 2 {
t.Fatal("TestCheckSignatures failed: OverloadFunc CheckSignatures ==", len(v))
}

if HasAutoProperty(of.Type()) {
t.Fatal("func bar has autoprop?")
}

if CheckSignatures(sigFuncEx(pkg, &TyTemplateRecvMethod{Func: of}), 0, 0) == nil {
t.Fatal("TestCheckSignatures failed: TemplateRecvMethod OverloadFunc CheckSignatures == nil")
}

o3 := types.NewFunc(token.NoPos, pkg, "bar2", sig)
of2 := NewOverloadFunc(token.NoPos, pkg, "bar3", o3)
if !HasAutoProperty(of2.Type()) {
t.Fatal("func bar3 has autoprop?")
}

typ := types.NewNamed(types.NewTypeName(token.NoPos, pkg, "t", nil), types.Typ[types.Int], nil)
om := NewOverloadMethod(typ, token.NoPos, pkg, "bar", o, o2)
if CheckSignatures(om.Type(), 0, 1) != nil {
t.Fatal("TestCheckSignatures failed: OverloadMethod CheckSignatures != nil")
}
}

func TestCheckSigParam(t *testing.T) {
if checkSigParam(types.NewPointer(types.Typ[types.Int]), -1) {
t.Fatal("TestCheckSigParam failed: checkSigParam *int should return false")
}
pkg := types.NewPackage("", "foo")
typ := types.NewNamed(types.NewTypeName(token.NoPos, pkg, "t", nil), types.Typ[types.Int], nil)
if !checkSigParam(typ, -1) {
t.Fatal("TestCheckSigParam failed: checkSigParam *t should return true")
}
typ2 := types.NewStruct(nil, nil)
if !checkSigParam(typ2, -1) {
t.Fatal("TestCheckSigParam failed: checkSigParam *t should return true")
}
typ3 := types.NewSlice(types.Typ[types.Int])
if !checkSigParam(typ3, -2) {
t.Fatal("TestCheckSigParam failed: checkSigParam []int should return true")
}
if checkSigParam(types.Typ[types.Int], -2) {
t.Fatal("TestCheckSigParam failed: checkSigParam int should return false")
}
}

func TestErrWriteFile(t *testing.T) {
pkg := NewPackage("", "foo", gblConf)
pkg.Types = nil
Expand Down
Loading

0 comments on commit ab3a59e

Please sign in to comment.