File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -316,6 +316,10 @@ func (c *codegen) emitStoreVar(pkg string, name string) {
316
316
return
317
317
}
318
318
vi := c .getVarIndex (pkg , name )
319
+ if vi .index == unspecifiedVarIndex && vi .ctx != nil {
320
+ c .scope .newLocal (name )
321
+ vi = c .getVarIndex (pkg , name )
322
+ }
319
323
c .emitStoreByIndex (vi .refType , vi .index )
320
324
}
321
325
Original file line number Diff line number Diff line change @@ -454,3 +454,47 @@ func TestInlineForeignType(t *testing.T) {
454
454
}`
455
455
eval (t , src , big .NewInt (29 ))
456
456
}
457
+
458
+ func TestInlineModifyArg (t * testing.T ) {
459
+ src := `package foo
460
+ import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/d"
461
+
462
+ func Main() int {
463
+ return d.Negate(-42)
464
+ }`
465
+ eval (t , src , big .NewInt (42 ))
466
+ }
467
+
468
+ func TestInlineMixedArgs (t * testing.T ) {
469
+ src := `package foo
470
+ import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/d"
471
+
472
+ func someCall() int { return 7 }
473
+
474
+ func Main() int {
475
+ return d.AddNeg(-3, someCall())
476
+ }`
477
+ eval (t , src , big .NewInt (- 4 ))
478
+ }
479
+
480
+ func TestInlineChain (t * testing.T ) {
481
+ src := `package foo
482
+ import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/d"
483
+
484
+ func Main() int {
485
+ return d.Wrap2(-2)
486
+ }`
487
+ eval (t , src , big .NewInt (2 ))
488
+ }
489
+
490
+ func TestInlineSlice (t * testing.T ) {
491
+ src := `package foo
492
+ import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline/d"
493
+
494
+ func Main() int {
495
+ s := make([]int, 1)
496
+ d.SetOneFirstElem(s)
497
+ return s[0]
498
+ }`
499
+ eval (t , src , big .NewInt (1 ))
500
+ }
Original file line number Diff line number Diff line change
1
+ package d
2
+
3
+ func Negate (n int ) int {
4
+ n *= - 1
5
+ return n
6
+ }
7
+
8
+ func AddNeg (a int , b int ) int {
9
+ a *= - 1
10
+ b *= - 1
11
+ return a + b
12
+ }
13
+
14
+ func Wrap1 (n int ) int {
15
+ n *= - 1
16
+ n *= - 1
17
+ return Negate (n )
18
+ }
19
+
20
+ func Wrap2 (n int ) int {
21
+ n *= - 1
22
+ n *= - 1
23
+ return Wrap1 (n )
24
+ }
25
+
26
+ func SetOneFirstElem (s []int ) {
27
+ s [0 ] = 1
28
+ }
You can’t perform that action at this time.
0 commit comments