mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
Merge pull request #1880 from nspcc-dev/compiler-inlining-fixes
Compiler inlining fixes
This commit is contained in:
commit
a44cd71b9d
3 changed files with 23 additions and 1 deletions
|
@ -162,7 +162,6 @@ func (c *codegen) countLocalsInline(decl *ast.FuncDecl, pkg *types.Package, f *f
|
||||||
switch n := n.(type) {
|
switch n := n.(type) {
|
||||||
case *ast.CallExpr:
|
case *ast.CallExpr:
|
||||||
size += c.countLocalsCall(n, pkg)
|
size += c.countLocalsCall(n, pkg)
|
||||||
return false
|
|
||||||
case *ast.FuncType:
|
case *ast.FuncType:
|
||||||
num := n.Results.NumFields()
|
num := n.Results.NumFields()
|
||||||
if num != 0 && len(n.Results.List[0].Names) != 0 {
|
if num != 0 && len(n.Results.List[0].Names) != 0 {
|
||||||
|
|
|
@ -209,6 +209,15 @@ func TestInlineGlobalVariable(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInlineVariadicInInlinedCall(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
||||||
|
func Main() int {
|
||||||
|
return inline.SumSquared(inline.SumVar(3, 4) - 2, 3)
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(64))
|
||||||
|
}
|
||||||
|
|
||||||
func TestInlineConversion(t *testing.T) {
|
func TestInlineConversion(t *testing.T) {
|
||||||
src1 := `package foo
|
src1 := `package foo
|
||||||
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
||||||
|
@ -255,3 +264,13 @@ func TestInlineConversionQualified(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, b2, b1)
|
require.Equal(t, b2, b1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPackageVarsInInlinedCalls(t *testing.T) {
|
||||||
|
src := `package foo
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline"
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/b"
|
||||||
|
func Main() int {
|
||||||
|
return inline.Sum(inline.A, b.A)
|
||||||
|
}`
|
||||||
|
eval(t, src, big.NewInt(13))
|
||||||
|
}
|
||||||
|
|
4
pkg/compiler/testdata/inline/inline.go
vendored
4
pkg/compiler/testdata/inline/inline.go
vendored
|
@ -39,6 +39,10 @@ func VarSum(a int, b ...int) int {
|
||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SumVar(a, b int) int {
|
||||||
|
return VarSum(a, b)
|
||||||
|
}
|
||||||
|
|
||||||
func Concat(n int) int {
|
func Concat(n int) int {
|
||||||
return n*100 + b.A*10 + A
|
return n*100 + b.A*10 + A
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue