Embedded struct fields are not supported by compiler #1447

Open
opened 2025-12-28 17:16:29 +00:00 by sami · 0 comments
Owner

Originally created by @roman-khimov on GitHub (Dec 10, 2024).

I'm always frustrated when I look at the code generated for embedded fields. So I try testing it and for

--- a/pkg/compiler/struct_test.go
+++ b/pkg/compiler/struct_test.go
@@ -397,6 +397,18 @@ var structTestCases = []testCase{
                `,
                big.NewInt(42),
        },
+       {
+               "embedded struct",
+               `type S11 struct { S10; b int }
+               func F%d() int {
+                       var s S11
+                       s.a = 31
+                       s.b = 11
+                       return s.a + s.b
+               }
+               `,
+               big.NewInt(42),
+       },
        {
                "omit field names",
                `type pair struct { a, b int }

I get

--- FAIL: TestStructs (0.02s)
    --- FAIL: TestStructs/embedded_struct (0.00s)
        vm_test.go:69: 
                Error Trace:    /home/rik/dev/neo-go/pkg/compiler/vm_test.go:69
                                                        /home/rik/dev/neo-go/pkg/compiler/struct_test.go:461
                Error:          Received unexpected error:
                                at instruction 499 (SETITEM): unhandled exception: "The value -1 is out of range."
                Test:           TestStructs/embedded_struct
FAIL
FAIL    github.com/nspcc-dev/neo-go/pkg/compiler        9.481s
FAIL

Describe the solution you'd like

Add proper support for it.

Originally created by @roman-khimov on GitHub (Dec 10, 2024). ## Is your feature request related to a problem? Please describe. I'm always frustrated when I look at the code generated for embedded fields. So I try testing it and for ``` --- a/pkg/compiler/struct_test.go +++ b/pkg/compiler/struct_test.go @@ -397,6 +397,18 @@ var structTestCases = []testCase{ `, big.NewInt(42), }, + { + "embedded struct", + `type S11 struct { S10; b int } + func F%d() int { + var s S11 + s.a = 31 + s.b = 11 + return s.a + s.b + } + `, + big.NewInt(42), + }, { "omit field names", `type pair struct { a, b int } ``` I get ``` --- FAIL: TestStructs (0.02s) --- FAIL: TestStructs/embedded_struct (0.00s) vm_test.go:69: Error Trace: /home/rik/dev/neo-go/pkg/compiler/vm_test.go:69 /home/rik/dev/neo-go/pkg/compiler/struct_test.go:461 Error: Received unexpected error: at instruction 499 (SETITEM): unhandled exception: "The value -1 is out of range." Test: TestStructs/embedded_struct FAIL FAIL github.com/nspcc-dev/neo-go/pkg/compiler 9.481s FAIL ``` ## Describe the solution you'd like Add proper support for it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neo-go#1447
No description provided.