diff --git a/pkg/compiler/inline.go b/pkg/compiler/inline.go index 74e33c190..57b0ed707 100644 --- a/pkg/compiler/inline.go +++ b/pkg/compiler/inline.go @@ -55,6 +55,15 @@ func (c *codegen) inlineCall(f *funcScope, n *ast.CallExpr) { copy(newScope, c.scope.vars.locals) defer c.scope.vars.dropScope() + if f.decl.Recv != nil { + c.scope.vars.locals = newScope + name := f.decl.Recv.List[0].Names[0].Name + c.scope.vars.addAlias(name, -1, unspecifiedVarIndex, &varContext{ + importMap: c.importMap, + expr: f.selector, + scope: oldScope, + }) + } hasVarArgs := !n.Ellipsis.IsValid() needPack := sig.Variadic() && hasVarArgs for i := range n.Args { diff --git a/pkg/compiler/inline_test.go b/pkg/compiler/inline_test.go index 3bbf38415..d8734ebd9 100644 --- a/pkg/compiler/inline_test.go +++ b/pkg/compiler/inline_test.go @@ -336,3 +336,22 @@ func TestPackageVarsInInlinedCalls(t *testing.T) { }` eval(t, src, big.NewInt(13)) } + +func TestInlinedMethod(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline" + func Main() int { + // It's important for this variable to not be named 't'. + var z inline.T + i := z.Inc(42) + if i != 0 || z.N != 42 { + return 0 + } + i = z.Inc(100500) + if i != 42 { + return 0 + } + return z.N + }` + eval(t, src, big.NewInt(100542)) +} diff --git a/pkg/compiler/testdata/inline/inline.go b/pkg/compiler/testdata/inline/inline.go index 62aaf2c79..dfc7aae4e 100644 --- a/pkg/compiler/testdata/inline/inline.go +++ b/pkg/compiler/testdata/inline/inline.go @@ -46,3 +46,13 @@ func SumVar(a, b int) int { func Concat(n int) int { return n*100 + b.A*10 + A } + +type T struct { + N int +} + +func (t *T) Inc(i int) int { + n := t.N + t.N += i + return n +}