Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print declared type in output #1143

Merged
merged 5 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/values_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
res := m.Eval(Call(Sel(&ConstExpr{TypedValue: *tv}, "Error")))
return res[0].GetString()
}
// print declared type
if _, ok := tv.T.(*DeclaredType); ok {
return tv.String()
}

Check warning on line 182 in gnovm/pkg/gnolang/values_string.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values_string.go#L181-L182

Added lines #L181 - L182 were not covered by tests
// otherwise, default behavior.
switch bt := baseOf(tv.T).(type) {
case PrimitiveType:
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/addr0b_stdlibs.gno
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ func main() {
}

// Output:
// struct{(struct{( string),( string),(0 int),(0 int),(nil github.com/gnolang/gno/_test/net/http.Header),(undefined),(0 int64),(nil []string),(false bool),( string),(nil github.com/gnolang/gno/_test/net/http.Values),(nil github.com/gnolang/gno/_test/net/http.Values),(nil github.com/gnolang/gno/_test/net/http.Header),( string),( string),(nil *github.com/gnolang/gno/_test/net/http.Response)} github.com/gnolang/gno/_test/net/http.Request),( string)}
// (struct{(struct{( string),( string),(0 int),(0 int),(nil github.com/gnolang/gno/_test/net/http.Header),(undefined),(0 int64),(nil []string),(false bool),( string),(nil github.com/gnolang/gno/_test/net/http.Values),(nil github.com/gnolang/gno/_test/net/http.Values),(nil github.com/gnolang/gno/_test/net/http.Header),( string),( string),(nil *github.com/gnolang/gno/_test/net/http.Response)} github.com/gnolang/gno/_test/net/http.Request),( string)} main.extendedRequest)
2 changes: 1 addition & 1 deletion gnovm/tests/files/assign21.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// 1 true
// (1 main.thing) true
2 changes: 1 addition & 1 deletion gnovm/tests/files/composite2.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ func main() {
}

// Output:
// struct{("hello" string)}
// (struct{("hello" string)} main.T)
2 changes: 1 addition & 1 deletion gnovm/tests/files/composite5.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ func main() {
}

// Output:
// struct{(12 uint16)}
// (struct{(12 uint16)} main.T)
2 changes: 1 addition & 1 deletion gnovm/tests/files/composite6.gno
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ func main() {
}

// Output:
// struct{(2 uint16)}
// (struct{(2 uint16)} main.T)
2 changes: 1 addition & 1 deletion gnovm/tests/files/const12.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// 0 2 4 6
// (0 main.Kind) (2 main.Kind) (4 main.Kind) (6 main.Kind)
2 changes: 1 addition & 1 deletion gnovm/tests/files/const15.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// 3
// (3 main.T1)
2 changes: 1 addition & 1 deletion gnovm/tests/files/fun6b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ func main() {
}

// Output:
// struct{(gonative{<nil>} gonative{*sync.Pool})}
// (struct{(gonative{<nil>} gonative{*sync.Pool})} main.Pool)
2 changes: 1 addition & 1 deletion gnovm/tests/files/fun9.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ func main() {
}

// Output:
// 1
// (1 main.myint)
2 changes: 1 addition & 1 deletion gnovm/tests/files/interface39b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ func main() {
}

// Output:
// struct{("bar" string)}
// (struct{("bar" string)} main.foo)
2 changes: 1 addition & 1 deletion gnovm/tests/files/map19b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// struct{(nil map[int64]*main.server)}
// (struct{(nil map[int64]*main.server)} main.cmap)
2 changes: 1 addition & 1 deletion gnovm/tests/files/ptr0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ func main() {
}

// Output:
// 2
// (2 main.myint)
2 changes: 1 addition & 1 deletion gnovm/tests/files/ptr7.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ func main() {
}

// Output:
// struct{(nil github.com/gnolang/gno/_test/net.IP),(nil github.com/gnolang/gno/_test/net.IPMask)}
// (struct{(nil github.com/gnolang/gno/_test/net.IP),(nil github.com/gnolang/gno/_test/net.IPMask)} main.ipNetValue)
4 changes: 2 additions & 2 deletions gnovm/tests/files/recurse0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func main() {
}

// Output:
// struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T)),(struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T))} main.U)}
// struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T))}
// (struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T)),(struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T))} main.U)} main.T)
// (struct{(nil []main.T),(nil []*main.T),(nil map[string]main.T),(nil map[string]*main.T),(nil chan main.T),(nil chan *main.T),(nil *main.T),(nil func(.arg_0 main.T)( main.T)),(nil func(.arg_0 *main.T)( *main.T))} main.U)
2 changes: 1 addition & 1 deletion gnovm/tests/files/struct28b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// struct{(struct{(nil *main.T1)} main.T2)}
// (struct{(struct{(nil *main.T1)} main.T2)} main.T1)
4 changes: 2 additions & 2 deletions gnovm/tests/files/struct50b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func main() {
}

// Output:
// struct{("hello" string),(slice[(struct{("world" string),(nil []main.Node)} main.Node)] []main.Node)}
// struct{("hello" string),(slice[(struct{("world" string),(slice[(struct{("sunshine" string),(nil []main.Node)} main.Node)] []main.Node)} main.Node)] []main.Node)}
// (struct{("hello" string),(slice[(struct{("world" string),(nil []main.Node)} main.Node)] []main.Node)} main.Node)
// (struct{("hello" string),(slice[(struct{("world" string),(slice[(struct{("sunshine" string),(nil []main.Node)} main.Node)] []main.Node)} main.Node)] []main.Node)} main.Node)
4 changes: 2 additions & 2 deletions gnovm/tests/files/struct52b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func main() {
}

// Output:
// struct{("hello" string),(map{("1" string):(struct{("world" string),(map{} map[string]main.Node)} main.Node)} map[string]main.Node)}
// struct{("hello" string),(map{("1" string):(struct{("world" string),(map{("1" string):(struct{("sunshine" string),(map{} map[string]main.Node)} main.Node)} map[string]main.Node)} main.Node)} map[string]main.Node)}
// (struct{("hello" string),(map{("1" string):(struct{("world" string),(map{} map[string]main.Node)} main.Node)} map[string]main.Node)} main.Node)
// (struct{("hello" string),(map{("1" string):(struct{("world" string),(map{("1" string):(struct{("sunshine" string),(map{} map[string]main.Node)} main.Node)} map[string]main.Node)} main.Node)} map[string]main.Node)} main.Node)
2 changes: 1 addition & 1 deletion gnovm/tests/files/struct53b.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ func main() {
}

// Output:
// struct{(nil *main.T)}
// (struct{(nil *main.T)} main.T2)
2 changes: 1 addition & 1 deletion gnovm/tests/files/type0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ func main() {
}

// Output:
// 0
// (0 main.newInt)
8 changes: 4 additions & 4 deletions gnovm/tests/files/zpersist_valids.gno
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func printVars(phase string) {
}

// Output:
// preinit 16 true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A struct{(16 int),("A" string)} 16 16 16 16 16 struct{(16 float32)} A
// postinit 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A struct{(32 int),("B" string)} 32 32 32 32 32 struct{("B" string)} B
// premain 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A struct{(32 int),("B" string)} 32 32 32 32 32 struct{("B" string)} B
// postmain 64 true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A struct{(64 int),("C" string)} 64 64 64 64 64 struct{("C" string)} C
// preinit 16 true 22 16.16 16.16 16 16 16 16 16 97 hello slice[("A" string)] A (struct{(16 int),("A" string)} gno.land/r/demo/tests_test.myStruct) 16 16 16 16 16 struct{(16 float32)} A
// postinit 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// premain 32 false 44 32.32 32.32 32 32 32 32 32 66 helloB slice[("A" string),("B" string)] A (struct{(32 int),("B" string)} gno.land/r/demo/tests_test.myStruct) 32 32 32 32 32 struct{("B" string)} B
// postmain 64 true 88 64.64 64.64 64 64 64 64 64 67 helloBC slice[("A" string),("B" string),("C" string)] A (struct{(64 int),("C" string)} gno.land/r/demo/tests_test.myStruct) 64 64 64 64 64 struct{("C" string)} C
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm10.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
}

// Output:
// struct{(1 int)}
// struct{(3 int)}
// (struct{(1 int)} gno.land/r/test.MyStruct)
// (struct{(3 int)} gno.land/r/test.MyStruct)

// Realm:
// switchrealm["gno.land/r/test"]
Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm11.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
}

// Output:
// struct{(1 int)}
// struct{(-1 int)}
// (struct{(1 int)} gno.land/r/test.MyStruct)
// (struct{(-1 int)} gno.land/r/test.MyStruct)

// Realm:
// switchrealm["gno.land/r/test"]
Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm8.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
}

// Output:
// struct{(1 int)}
// struct{(2 int)}
// (struct{(1 int)} gno.land/r/test.MyStruct)
// (struct{(2 int)} gno.land/r/test.MyStruct)

// Realm:
// switchrealm["gno.land/r/test"]
Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/zrealm9.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
}

// Output:
// struct{(1 int)}
// struct{(0 int)}
// (struct{(1 int)} gno.land/r/test.MyStruct)
// (struct{(0 int)} gno.land/r/test.MyStruct)

// Realm:
// switchrealm["gno.land/r/test"]
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_crossrealm0.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func main() {
}

// Output:
// struct{("test" string)}
// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject)
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_crossrealm1.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ func main() {
}

// Output:
// struct{("test" string)}
// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject)
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_crossrealm6.gno
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ func main() {
}

// Output:
// struct{("modified" string)}
// (struct{("modified" string)} gno.land/p/demo/tests.TestRealmObject2)
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_std1.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
}

// Output:
// slice[ref(1ed29bd278d735e20e296bd4afe927501941392f:4)]
// (slice[ref(1ed29bd278d735e20e296bd4afe927501941392f:4)] std.AddressList)
// error: address already exists
// has: true
// has: false
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_std2.gno
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
}

// Output:
// slice[ref(1ed29bd278d735e20e296bd4afe927501941392f:4)]
// (slice[ref(1ed29bd278d735e20e296bd4afe927501941392f:4)] std.AddressList)
// error: address already exists
// has: true
// has: false
Loading