diff --git a/contracts/assign_unnamed_type/append_named_unnamed_type_filetest.gno b/contracts/assign_unnamed_type/append_named_unnamed_type_filetest.gno new file mode 100644 index 00000000000..f9ebb53eeff --- /dev/null +++ b/contracts/assign_unnamed_type/append_named_unnamed_type_filetest.gno @@ -0,0 +1,38 @@ +package main + + + +type nat []int + +func main() { + + var nlist = nat{0} + var ulist = []int{1} + var n int = 3 + + a := append(nlist, n) + b := append(ulist, n) + + println(a) + println(b) + + a = append(ulist, n) + b = append(nlist, n) + + c := append(nlist, ulist...) + d := append(ulist, nlist...) + + println(a) + println(b) + println(c) + println(d) + +} + +// Output: +// (slice[(0 int),(3 int)] main.nat) +// slice[(1 int),(3 int)] +// (slice[(1 int),(3 int)] main.nat) +// slice[(0 int),(3 int)] +// (slice[(0 int),(1 int)] main.nat) +// slice[(1 int),(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype0_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype0_filetest.gno new file mode 100644 index 00000000000..c722fa50c9c --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype0_filetest.gno @@ -0,0 +1,15 @@ +package main + +type nat []word +type word int + +func main() { + var a nat + b := []word{0} + a = b + + println(a) +} + +// Output: +// (slice[(0 main.word)] main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno new file mode 100644 index 00000000000..b9db1871254 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno @@ -0,0 +1,15 @@ +package main + +type nat []int +type word int + +func main() { + var a nat + b := []word{0} + a = b + + println(a) +} + +// Error: +// main/contracts/assign_unnamed_type/assign_unnamedtype0b_filetest.gno:9: cannot use main.word as int without explicit conversion diff --git a/contracts/assign_unnamed_type/assign_unnamedtype1_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype1_filetest.gno new file mode 100644 index 00000000000..35a2fef7c51 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype1_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func main() { + + var a nat + a = []int{0} + b := []int{1} + + println(a) + println(b) + + a = nat{0} + b = a + + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype1a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype1a_filetest.gno new file mode 100644 index 00000000000..cb13467ecdc --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype1a_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func (n nat) zero(num []int) { + println(num) + +} + +func (n nat) one(num nat) { + + println(num) +} + +func main() { + var a nat + a = []int{} + + a.zero(nat{0}) + a.one([]int{1}) + +} + +// Output: +// slice[(0 int)] +// (slice[(1 int)] main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype1b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype1b_filetest.gno new file mode 100644 index 00000000000..752a10f7ecf --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype1b_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat []int + +func (n nat) zero() nat { + + return []int{0} +} + +func (n nat) one() []int { + + return nat{1} +} + +func main() { + var a nat + a = []int{} + + println(a.zero()) + println(a.zero().zero()) + println(a.zero().one()) + println(a.one()) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// slice[(1 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype1c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype1c_filetest.gno new file mode 100644 index 00000000000..621d478a811 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype1c_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat []int + +func (n nat) zero() interface{} { + + return []int{0} +} + +func (n nat) one() interface{} { + + return nat{1} +} + +func main() { + var a nat + a = []int{} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// slice[(0 int)] +// (slice[(1 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype2_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype2_filetest.gno new file mode 100644 index 00000000000..9148def9d91 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype2_filetest.gno @@ -0,0 +1,25 @@ +package main + +type nat [1]int + +func main() { + + var a nat + a = [1]int{0} + b := [1]int{1} + + println(a) + println(b) + a = nat{0} + b = a + + println(a) + println(b) + +} + +// Output: +// (array[(0 int)] main.nat) +// array[(1 int)] +// (array[(0 int)] main.nat) +// array[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype2a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype2a_filetest.gno new file mode 100644 index 00000000000..754507055b1 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype2a_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat [1]int + +func (n nat) zero(num [1]int) { + println(num) + +} + +func (n nat) one(num nat) { + + println(num) +} + +func main() { + var a nat + a = [1]int{} + + a.zero(nat{0}) + a.one([1]int{1}) + +} + +// Output: +// array[(0 int)] +// (array[(1 int)] main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype2b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype2b_filetest.gno new file mode 100644 index 00000000000..9ac3ed6f97a --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype2b_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat [1]int + +func (n nat) zero() nat { + + return [1]int{0} +} + +func (n nat) one() [1]int { + + return nat{1} +} + +func main() { + var a nat + a = [1]int{} + + println(a.zero()) + println(a.zero().zero()) + println(a.zero().one()) + println(a.one()) + +} + +// Output: +// (array[(0 int)] main.nat) +// (array[(0 int)] main.nat) +// array[(1 int)] +// array[(1 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype2c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype2c_filetest.gno new file mode 100644 index 00000000000..ee2057251db --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype2c_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat [1]int + +func (n nat) zero() interface{} { + + return [1]int{0} +} + +func (n nat) one() interface{} { + + return nat{1} +} + +func main() { + var a nat + a = [1]int{} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// array[(0 int)] +// (array[(1 int)] main.nat) +// array[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype3_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype3_filetest.gno new file mode 100644 index 00000000000..aa466be2216 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype3_filetest.gno @@ -0,0 +1,27 @@ +package main + +type nat struct { + num int +} + +func main() { + + var a nat + a = struct{ num int }{0} + b := struct{ num int }{1} + + println(a) + println(b) + a = nat{0} + b = a + + println(a) + println(b) + +} + +// Output: +// (struct{(0 int)} main.nat) +// struct{(1 int)} +// (struct{(0 int)} main.nat) +// struct{(0 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype3a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype3a_filetest.gno new file mode 100644 index 00000000000..385bbaaf43c --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype3a_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat struct { + num int +} + +func (n nat) zero(num struct{ num int }) { + println(num) + +} + +func (n nat) one(num nat) { + + println(num) +} + +func main() { + var a nat + a = struct{ num int }{0} + + a.zero(nat{0}) + a.one(struct{ num int }{1}) + +} + +// Output: +// struct{(0 int)} +// (struct{(1 int)} main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype3b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype3b_filetest.gno new file mode 100644 index 00000000000..4e34cf38ad7 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype3b_filetest.gno @@ -0,0 +1,32 @@ +package main + +type nat struct { + num int +} + +func (n nat) zero() nat { + + return struct{ num int }{0} +} + +func (n nat) one() struct{ num int } { + + return nat{1} +} + +func main() { + var a nat + a = struct{ num int }{} + + println(a.zero()) + println(a.zero().zero()) + println(a.zero().one()) + println(a.one()) + +} + +// Output: +// (struct{(0 int)} main.nat) +// (struct{(0 int)} main.nat) +// struct{(1 int)} +// struct{(1 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype3c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype3c_filetest.gno new file mode 100644 index 00000000000..d0e1a1bbffe --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype3c_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat struct { + num int +} + +func (n nat) zero() interface{} { + + return struct{ num int }{0} +} + +func (n nat) one() interface{} { + + return nat{1} +} + +func main() { + var a nat + a = struct{ num int }{} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// struct{(0 int)} +// (struct{(1 int)} main.nat) +// struct{(0 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype4_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype4_filetest.gno new file mode 100644 index 00000000000..5fe5b4f11a9 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype4_filetest.gno @@ -0,0 +1,29 @@ +package main + +type nat map[string]int + +func main() { + + var a nat + + a = map[string]int{ + "zero": 0, + } + b := map[string]int{ + "one": 1, + } + println(a) + println(b) + + a = nat{"zeor": 0} + b = a + println(a) + println(b) + +} + +// Output: +// (map{("zero" string):(0 int)} main.nat) +// map{("one" string):(1 int)} +// (map{("zeor" string):(0 int)} main.nat) +// map{("zeor" string):(0 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype4a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype4a_filetest.gno new file mode 100644 index 00000000000..dd56f229be2 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype4a_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat map[string]int + +func (n nat) zero(num map[string]int) { + println(num) + +} + +func (n nat) one(num nat) { + + println(num) +} + +func main() { + var a nat + a = map[string]int{ + "zero": 0, + } + + a.zero(nat{"zero": 0}) + a.one(map[string]int{ + "zero": 1, + }) + +} + +// Output: +// map{("zero" string):(0 int)} +// (map{("zero" string):(1 int)} main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype4b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype4b_filetest.gno new file mode 100644 index 00000000000..8a6ef440ee8 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype4b_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat map[string]int + +func (n nat) zero() nat { + + return map[string]int{"zero": 0} +} + +func (n nat) one() map[string]int { + + return nat{"one": 1} +} + +func main() { + var a nat + a = map[string]int{"zero": 0} + + println(a.zero()) + println(a.zero().zero()) + println(a.zero().one()) + println(a.one()) + +} + +// Output: +// (map{("zero" string):(0 int)} main.nat) +// (map{("zero" string):(0 int)} main.nat) +// map{("one" string):(1 int)} +// map{("one" string):(1 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype4c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype4c_filetest.gno new file mode 100644 index 00000000000..30b9db76eee --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype4c_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat map[string]int + +func (n nat) zero() interface{} { + + return map[string]int{"zero": 0} +} + +func (n nat) one() interface{} { + + return nat{"one": 1} +} + +func main() { + var a nat + a = map[string]int{"zero": 0} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// map{("zero" string):(0 int)} +// (map{("one" string):(1 int)} main.nat) +// map{("zero" string):(0 int)} diff --git a/contracts/assign_unnamed_type/assign_unnamedtype5_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype5_filetest.gno new file mode 100644 index 00000000000..da1da6ce906 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype5_filetest.gno @@ -0,0 +1,44 @@ +package main + +type op func(int) int + +func inc(n int) int { + + n = n + 1 + return n +} +func dec(n int) int { + + n = n - 1 + return n +} + +func main() { + var a op + a = inc + + b := func(n int) int { + + return n + } + c := dec + + println(a(0), a) + println(b(0), b) + println(c(0), c) + + a, b, c = b, c, a + + println(a(0), a) + println(b(0), b) + println(c(0), c) + +} + +// Output: +// 1 (inc main.op) +// 0 +// -1 dec +// 0 ( main.op) +// -1 dec +// 1 inc diff --git a/contracts/assign_unnamed_type/assign_unnamedtype5a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype5a_filetest.gno new file mode 100644 index 00000000000..2cdbabab1d5 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype5a_filetest.gno @@ -0,0 +1,37 @@ +package main + +type op func(int) int + +func exec1(opFn func(int) int) { + println(opFn) + println(opFn(0)) + +} + +func exec2(opFn op) { + + println(opFn) + println(opFn(0)) +} + +func main() { + var inc op + inc = func(n int) int { + + n = n + 1 + return n + } + dec := func(n int) int { + + n = n - 1 + return n + } + exec1(inc) + exec2(dec) + +} + +// Output: +// 1 +// ( main.op) +// -1 diff --git a/contracts/assign_unnamed_type/assign_unnamedtype5b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype5b_filetest.gno new file mode 100644 index 00000000000..31055fed80d --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype5b_filetest.gno @@ -0,0 +1,37 @@ +package main + +type op func(int) int + +func popFn1() op { + + return func(n int) int { + + n = n + 1 + return n + + } +} + +func popFn2() func(int) int { + var dec op + + dec = func(n int) int { + + n = n - 1 + return n + + } + + return dec +} + +func main() { + + println(popFn1()(0)) + println(popFn2()(0)) + +} + +// Output: +// 1 +// -1 diff --git a/contracts/assign_unnamed_type/assign_unnamedtype5c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype5c_filetest.gno new file mode 100644 index 00000000000..621d478a811 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype5c_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat []int + +func (n nat) zero() interface{} { + + return []int{0} +} + +func (n nat) one() interface{} { + + return nat{1} +} + +func main() { + var a nat + a = []int{} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// slice[(0 int)] +// (slice[(1 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype6_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype6_filetest.gno new file mode 100644 index 00000000000..cc9aad71ec2 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype6_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []interface{} + +func main() { + + var a nat + a = []interface{}{0} + b := []interface{}{1} + + println(a) + println(b) + + a = nat{0} + b = a + + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype6a_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype6a_filetest.gno new file mode 100644 index 00000000000..6fc993708c8 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype6a_filetest.gno @@ -0,0 +1,27 @@ +package main + +type nat []interface{} + +func (n nat) zero(num []interface{}) { + println(num) + +} + +func (n nat) one(num nat) { + println(num) +} + +func main() { + + var a nat + a = []interface{}{} + println(a) + a.zero(nat{0}) + a.one([]interface{}{1}) + +} + +// Output: +// (slice[] main.nat) +// slice[(0 int)] +// (slice[(1 int)] main.nat) diff --git a/contracts/assign_unnamed_type/assign_unnamedtype6b_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype6b_filetest.gno new file mode 100644 index 00000000000..2fc593f7bc1 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype6b_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat []interface{} + +func (n nat) zero() nat { + return []interface{}{0} + +} + +func (n nat) one() []interface{} { + return nat{1} +} + +func main() { + + var a nat + a = []interface{}{} + + println(a.zero()) + println(a.zero().zero()) + println(a.zero().one()) + println(a.one()) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// slice[(1 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype6c_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype6c_filetest.gno new file mode 100644 index 00000000000..1e80a93ab1b --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype6c_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat []interface{} + +func (n nat) zero() interface{} { + + return []interface{}{0} +} + +func (n nat) one() interface{} { + + return nat{1} +} + +func main() { + var a nat + a = []interface{}{} + + println(a.zero()) + println(a.one()) + println(a.one().(nat).zero()) + +} + +// Output: +// slice[(0 int)] +// (slice[(1 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/assign_unnamed_type/assign_unnamedtype7_filetest.gno b/contracts/assign_unnamed_type/assign_unnamedtype7_filetest.gno new file mode 100644 index 00000000000..939428bd192 --- /dev/null +++ b/contracts/assign_unnamed_type/assign_unnamedtype7_filetest.gno @@ -0,0 +1,15 @@ +package main + +type mychan chan int + +// chan int is unmamed +func main() { + var n mychan = nil + var u chan int = nil + n = u + + println(n) +} + +// Output: +// (nil main.mychan) diff --git a/contracts/assign_unnamed_type/copy_name_unnamed2_type_filetest.gno b/contracts/assign_unnamed_type/copy_name_unnamed2_type_filetest.gno new file mode 100644 index 00000000000..6cad44a4afe --- /dev/null +++ b/contracts/assign_unnamed_type/copy_name_unnamed2_type_filetest.gno @@ -0,0 +1,21 @@ +package main + + +type nat []int +type nat2 []int + +func main() { + + var nlist = nat{0} + var n2list = nat2{1} + + copy(nlist, n2list) + + + println(nlist) + + +} + +// Output: +// (slice[(1 int)] main.nat) diff --git a/contracts/assign_unnamed_type/copy_name_unnamed_type_filetest.gno b/contracts/assign_unnamed_type/copy_name_unnamed_type_filetest.gno new file mode 100644 index 00000000000..6ada04f3a9a --- /dev/null +++ b/contracts/assign_unnamed_type/copy_name_unnamed_type_filetest.gno @@ -0,0 +1,27 @@ +package main + +type nat []int + +func main() { + + var nlist = nat{0} + var ulist = []int{1} + + copy(nlist, ulist) + + println(nlist) + println(ulist) + + nlist = nat{0} + ulist = []int{1} + copy(ulist, nlist) + println(nlist) + println(ulist) + +} + +// Output: +// (slice[(1 int)] main.nat) +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/declaredtype/declaredType0_filetest.gno b/contracts/declaredtype/declaredType0_filetest.gno new file mode 100644 index 00000000000..4aa8ff10d97 --- /dev/null +++ b/contracts/declaredtype/declaredType0_filetest.gno @@ -0,0 +1,17 @@ +package main + +type word uint +type nat []word + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + abs = []word{0} + println(abs.add()) +} + +// Output: +// true diff --git a/contracts/declaredtype/declaredType0b_filetest.gno b/contracts/declaredtype/declaredType0b_filetest.gno new file mode 100644 index 00000000000..b053442c2d4 --- /dev/null +++ b/contracts/declaredtype/declaredType0b_filetest.gno @@ -0,0 +1,20 @@ +package main + +type word int +type nat []word + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + var b []word + b = []word{0} + abs = b + + println(abs) +} + +// Output: +// (slice[(0 main.word)] main.nat) diff --git a/contracts/declaredtype/declaredType1_filetest.gno b/contracts/declaredtype/declaredType1_filetest.gno new file mode 100644 index 00000000000..2a0d1f5c500 --- /dev/null +++ b/contracts/declaredtype/declaredType1_filetest.gno @@ -0,0 +1,25 @@ +package main + + type word uint + type nat []word + + // structLit + type Int struct { + neg bool + abs nat + } + + func (n nat) add() bool { + return true + } + + func main() { + z := &Int{ + neg: true, + abs: []word{0}, + } + println(z.abs.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType1b_filetest.gno b/contracts/declaredtype/declaredType1b_filetest.gno new file mode 100644 index 00000000000..e4f53cb172a --- /dev/null +++ b/contracts/declaredtype/declaredType1b_filetest.gno @@ -0,0 +1,25 @@ +package main + + type word uint + type nat []word + + type Int struct { + neg bool + abs nat + } + + func (n nat) add() bool { + return true + } + + func main() { + z := &Int{ + neg: true, + } + + z.abs = []word{0} + println(z.abs.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType2_filetest.gno b/contracts/declaredtype/declaredType2_filetest.gno new file mode 100644 index 00000000000..3417d9a6f9c --- /dev/null +++ b/contracts/declaredtype/declaredType2_filetest.gno @@ -0,0 +1,25 @@ +package main + +type word uint +type nat []word + +func (n nat) add() bool { + return true +} + +// map +func main() { + items := map[string]nat{} + + n := []word{0} + + // this is assignment + items["test"] = n + + r := items["test"] + + println(r.add()) +} + +// Output: +// true diff --git a/contracts/declaredtype/declaredType2b_filetest.gno b/contracts/declaredtype/declaredType2b_filetest.gno new file mode 100644 index 00000000000..9d37b0dbaee --- /dev/null +++ b/contracts/declaredtype/declaredType2b_filetest.gno @@ -0,0 +1,24 @@ +package main + + type word uint + type nat []word + + func (n nat) add() bool { + return true + } + + // mapLit + func main() { + n := []word{0} + + items := map[string]nat{ + "test": n, + } + + r := items["test"] + + println(r.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType3_filetest.gno b/contracts/declaredtype/declaredType3_filetest.gno new file mode 100644 index 00000000000..c2a98cb3a3a --- /dev/null +++ b/contracts/declaredtype/declaredType3_filetest.gno @@ -0,0 +1,20 @@ +package main + + type word uint + type nat []word + + func (n nat) add() bool { + return true + } + + // sliceLit + func main() { + items := []nat{[]word{0}, []word{1}} + + r := items[0] + + println(r.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType3b_filetest.gno b/contracts/declaredtype/declaredType3b_filetest.gno new file mode 100644 index 00000000000..960197f5c04 --- /dev/null +++ b/contracts/declaredtype/declaredType3b_filetest.gno @@ -0,0 +1,20 @@ +package main + + type word uint + type nat []word + + func (n nat) add() bool { + return true + } + + // sliceLit2 + func main() { + items := []nat{1:[]word{0}, 2:[]word{1}} + + r := items[1] + + println(r.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType3c_filetest.gno b/contracts/declaredtype/declaredType3c_filetest.gno new file mode 100644 index 00000000000..15a2fc048ac --- /dev/null +++ b/contracts/declaredtype/declaredType3c_filetest.gno @@ -0,0 +1,24 @@ +package main + + type word uint + type nat []word + + func (n nat) add() bool { + return true + } + + // slice append + func main() { + var items []nat + + n := []word{0} + + items = append(items, n) + + r := items[0] + + println(r.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType3d_filetest.gno b/contracts/declaredtype/declaredType3d_filetest.gno new file mode 100644 index 00000000000..5b3148a4c94 --- /dev/null +++ b/contracts/declaredtype/declaredType3d_filetest.gno @@ -0,0 +1,20 @@ +package main + + type word uint + type nat []word + + func (n nat) add() bool { + return true + } + + // ArrayLit + func main() { + items := [3]nat{[]word{0}, []word{1}} + + r := items[0] + + println(r.add()) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType4_filetest.gno b/contracts/declaredtype/declaredType4_filetest.gno new file mode 100644 index 00000000000..69bd9206aed --- /dev/null +++ b/contracts/declaredtype/declaredType4_filetest.gno @@ -0,0 +1,22 @@ +package main + + + type word uint + type nat []word + + func (n nat) add(x, y nat) bool { + return true + } + + // parameter + func main() { + var abs nat + abs = []word{0} + x := []word{1} + y := []word{2} + + println(abs.add(x, y)) + } + + // Output: + // true \ No newline at end of file diff --git a/contracts/declaredtype/declaredType5_filetest.gno b/contracts/declaredtype/declaredType5_filetest.gno new file mode 100644 index 00000000000..ee22bb38c30 --- /dev/null +++ b/contracts/declaredtype/declaredType5_filetest.gno @@ -0,0 +1,22 @@ +package main + + type BasicFunc func(int, int) int + type MyFunc BasicFunc + + func (f MyFunc) Apply(a, b int) int { + return f(a, b) + } + + func main() { + basicAdd := func(a, b int) int { + return a + b + } + var myAdd MyFunc + myAdd = basicAdd + + result := myAdd.Apply(2, 3) + println(result) + } + + // Output: + // 5 \ No newline at end of file diff --git a/contracts/declaredtype/declaredType6_filetest.gno b/contracts/declaredtype/declaredType6_filetest.gno new file mode 100644 index 00000000000..fbb6c323dbf --- /dev/null +++ b/contracts/declaredtype/declaredType6_filetest.gno @@ -0,0 +1,20 @@ +package main + +type c uint +type word c +type nat []word + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + + abs = []c{0} + + println(abs.add()) +} + +// Error: +// main/contracts/declaredtype/declaredType6_filetest.gno:14: cannot use main.c as main.word without explicit conversion diff --git a/contracts/declaredtype/declaredType6b_filetest.gno b/contracts/declaredtype/declaredType6b_filetest.gno new file mode 100644 index 00000000000..dfca37a188e --- /dev/null +++ b/contracts/declaredtype/declaredType6b_filetest.gno @@ -0,0 +1,20 @@ +package main + +type c uint +type word c +type nat []word + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + + abs = []uint{0} + + println(abs.add()) +} + +// Error: +// main/contracts/declaredtype/declaredType6b_filetest.gno:14: cannot use uint as main.word without explicit conversion diff --git a/contracts/decompose/decompose_unnamed1a_filetest.gno b/contracts/decompose/decompose_unnamed1a_filetest.gno new file mode 100644 index 00000000000..aff909afcd5 --- /dev/null +++ b/contracts/decompose/decompose_unnamed1a_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{1} + b := []int{2} + return a, b +} + +func main() { + var u1 []int + var n2 nat + + _, n2 = x() + // _tmp1, _tmp_2 := x() + // _, u2 = _tmp1, _tmp_2 + + println(u1) + println(n2) + +} + +// Output: +// (nil []int) +// (slice[(2 int)] main.nat) diff --git a/contracts/decompose/decompose_unnamed1b_filetest.gno b/contracts/decompose/decompose_unnamed1b_filetest.gno new file mode 100644 index 00000000000..3248d9ca700 --- /dev/null +++ b/contracts/decompose/decompose_unnamed1b_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{1} + b := []int{2} + return a, b +} + +func main() { + var u1 []int + var n2 nat + + u1, _ = x() + // _tmp1, _tmp_2 := x() + // u1, _ = _tmp1, _tmp_2 + + println(u1) + println(n2) + +} + +// Output: +// slice[(1 int)] +// (nil main.nat) diff --git a/contracts/decompose/decompose_unnamed2_filetest.gno b/contracts/decompose/decompose_unnamed2_filetest.gno new file mode 100644 index 00000000000..e28b231b63e --- /dev/null +++ b/contracts/decompose/decompose_unnamed2_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{1} + b := []int{2} + return a, b +} + +func main() { + var u1 []int + var n2 nat + // BlockStmt + { u1, n2 = x() + // _tmp_1, _tmp_2 := x() + // u1, n2 = _tmp_1, _tmp_2 + + println(u1) + println(n2) + println(u1) + println(n2) + } +} + +// Output: +// slice[(1 int)] +// (slice[(2 int)] main.nat) +// slice[(1 int)] +// (slice[(2 int)] main.nat) diff --git a/contracts/decompose/decompose_unnamed_filetest.gno b/contracts/decompose/decompose_unnamed_filetest.gno new file mode 100644 index 00000000000..b2f8840e7f0 --- /dev/null +++ b/contracts/decompose/decompose_unnamed_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{1} + b := []int{2} + return a, b +} + +func main() { + var u1 []int + var n2 nat + + u1, n2 = x() + // _tmp_1, _tmp_2 := x() + // u1, n2 = _tmp_1, _tmp_2 + + println(u1) + println(n2) + +} + +// Output: +// slice[(1 int)] +// (slice[(2 int)] main.nat) diff --git a/contracts/filetest/assignment_filetest.gno b/contracts/filetest/assignment_filetest.gno new file mode 100644 index 00000000000..ebcbcff37a1 --- /dev/null +++ b/contracts/filetest/assignment_filetest.gno @@ -0,0 +1,27 @@ +package main + +type nat []int + +func main() { + var a nat + var b []int + + a = []int{0} + b = nat{1} + + println(a) + println(b) + + a = b + b = a + + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(1 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/filetest/convert_types1b_filetest.gno.bk b/contracts/filetest/convert_types1b_filetest.gno.bk new file mode 100644 index 00000000000..593c02204a5 --- /dev/null +++ b/contracts/filetest/convert_types1b_filetest.gno.bk @@ -0,0 +1,19 @@ +package main + +type nat []int + +func main() { + var a nat + var b []int + + a = (nat)([]int{0}) + b = ([]int)(nat{1}) + println(a) + println(b) + + a = (nat)(b) + b = ([]int)(a) + println(a) + println(b) + +} diff --git a/contracts/filetest/convert_types_filetest.gno b/contracts/filetest/convert_types_filetest.gno new file mode 100644 index 00000000000..4fd038a60cc --- /dev/null +++ b/contracts/filetest/convert_types_filetest.gno @@ -0,0 +1,23 @@ +package main + +type nat []int + +func main() { + + var b []int + b = nat{1} + println(b) + + var a nat + a = []int{0} + println(a) + + b = a + println(b) + +} + +//Output: +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/filetest/declaredtype2_filetest.gno b/contracts/filetest/declaredtype2_filetest.gno new file mode 100644 index 00000000000..6c2e0fa38d6 --- /dev/null +++ b/contracts/filetest/declaredtype2_filetest.gno @@ -0,0 +1,32 @@ +package main + +type nat []Word +type Word uint + +func main() { + var abs []Word + abs = nat{0} // abs is a not named array + println(abs) + println() + a := []Word{0} + b := nat{0} + c := a + d := b + e := abs + + println(a) + println(b) + println(c) + println(d) + println(e) + +} + +// Output: +// slice[(0 main.Word)] +// +// slice[(0 main.Word)] +// (slice[(0 main.Word)] main.nat) +// slice[(0 main.Word)] +// (slice[(0 main.Word)] main.nat) +// slice[(0 main.Word)] diff --git a/contracts/filetest/default_value_filetest.gno b/contracts/filetest/default_value_filetest.gno new file mode 100644 index 00000000000..5612f9a84d4 --- /dev/null +++ b/contracts/filetest/default_value_filetest.gno @@ -0,0 +1,30 @@ +package main +type nat []int +type nmap map[int]int +type nfunc func() + +func main() { + var u1 []int + var n2 nat + var m map[int]int + var m2 nmap + var f func() + var f2 nfunc + + + println(u1) + println(n2) + println(m) + println(m2) + println(f) + println(f2) + +} + +// Output: +// (nil []int) +// (nil main.nat) +// (nil map[int]int) +// (nil main.nmap) +// nil func()() +// (nil main.nfunc) diff --git a/contracts/filetest/method38d_filetest.gno b/contracts/filetest/method38d_filetest.gno new file mode 100644 index 00000000000..48599c922ba --- /dev/null +++ b/contracts/filetest/method38d_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []Word +type Word uint + +func (n nat) add() nat { + + return []Word{0} +} + +func main() { + var abs nat + abs = []Word{0} + println(abs) + println(abs.add().add()) +} + +// Output: +// (slice[(0 main.Word)] main.nat) +// (slice[(0 main.Word)] main.nat) diff --git a/contracts/filetest/method38e_filetest.gno b/contracts/filetest/method38e_filetest.gno new file mode 100644 index 00000000000..ba99f45adb3 --- /dev/null +++ b/contracts/filetest/method38e_filetest.gno @@ -0,0 +1,21 @@ +package main + +type nat []Word +type Word uint + +func (n nat) add() []Word { + + return nat{0} +} + +func main() { + var abs nat + abs = []Word{0} + println(abs) + println(abs.add()) + // println(abs.add().add()) // it should build failed. +} + +// Output: +// (slice[(0 main.Word)] main.nat) +// slice[(0 main.Word)] diff --git a/contracts/filetest/method38e_filetest0.gno b/contracts/filetest/method38e_filetest0.gno new file mode 100644 index 00000000000..ba99f45adb3 --- /dev/null +++ b/contracts/filetest/method38e_filetest0.gno @@ -0,0 +1,21 @@ +package main + +type nat []Word +type Word uint + +func (n nat) add() []Word { + + return nat{0} +} + +func main() { + var abs nat + abs = []Word{0} + println(abs) + println(abs.add()) + // println(abs.add().add()) // it should build failed. +} + +// Output: +// (slice[(0 main.Word)] main.nat) +// slice[(0 main.Word)] diff --git a/contracts/filetest/method38g_filetest.gno b/contracts/filetest/method38g_filetest.gno new file mode 100644 index 00000000000..f2f4509e82a --- /dev/null +++ b/contracts/filetest/method38g_filetest.gno @@ -0,0 +1,30 @@ +package main + +type nat []Word +type Word uint + +func (n nat) add(ws []Word) interface{} { + println(ws) + + return ws +} +func (n nat) add2(ws nat) interface{} { + println(ws) + + return ws +} +func main() { + var abs nat + abs = []Word{0} + + println(abs.add(abs)) + println() + println(abs.add2(abs)) +} + +// Output: +// slice[(0 main.Word)] +// slice[(0 main.Word)] +// +// (slice[(0 main.Word)] main.nat) +// (slice[(0 main.Word)] main.nat) diff --git a/contracts/filetest/realm_compositelit_filetest.gno b/contracts/filetest/realm_compositelit_filetest.gno new file mode 100644 index 00000000000..1efa2348052 --- /dev/null +++ b/contracts/filetest/realm_compositelit_filetest.gno @@ -0,0 +1,225 @@ +// PKGPATH: gno.land/r/test +package test + +import ( + "fmt" +) + +type word uint +type nat []word + +var zero *Int + +// structLit +type Int struct { + abs nat +} + +func main() { + + zero = &Int{ + abs: []word{0}, + } + a := zero.abs + println(a) +} + +// Output: +// (slice[(0 gno.land/r/test.word)] gno.land/r/test.nat) + +// Realm: +// switchrealm["gno.land/r/test"] +// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:5]={ +// "Data": null, +// "List": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.word" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5", +// "ModTime": "0", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "RefCount": "1" +// } +// } +// c[a8ada09dee16d791fd406d629fe29bb0ed084a30:4]={ +// "Fields": [ +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.nat" +// }, +// "V": { +// "@type": "/gno.SliceValue", +// "Base": { +// "@type": "/gno.RefValue", +// "Hash": "9263ebf7e55e2d929e9c190bc4490ee58db148ec", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:5" +// }, +// "Length": "1", +// "Maxcap": "1", +// "Offset": "0" +// } +// } +// ], +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4", +// "ModTime": "0", +// "OwnerID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", +// "RefCount": "1" +// } +// } +// u[a8ada09dee16d791fd406d629fe29bb0ed084a30:2]={ +// "Blank": {}, +// "ObjectInfo": { +// "ID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:2", +// "IsEscaped": true, +// "ModTime": "3", +// "RefCount": "2" +// }, +// "Parent": null, +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "", +// "Line": "0", +// "Nonce": "0", +// "PkgPath": "gno.land/r/test" +// } +// }, +// "Values": [ +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.PrimitiveType", +// "value": "2048" +// }, +// "Methods": [], +// "Name": "word", +// "PkgPath": "gno.land/r/test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.word" +// }, +// "Vrd": false +// }, +// "Methods": [], +// "Name": "nat", +// "PkgPath": "gno.land/r/test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "abs", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.nat" +// } +// } +// ], +// "PkgPath": "gno.land/r/test" +// }, +// "Methods": [], +// "Name": "Int", +// "PkgPath": "gno.land/r/test" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:3" +// }, +// "FileName": "main.gno", +// "IsMethod": false, +// "Name": "main", +// "PkgPath": "gno.land/r/test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "main.gno", +// "Line": "18", +// "Nonce": "0", +// "PkgPath": "gno.land/r/test" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.Int" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": null, +// "Index": "0", +// "TV": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/test.Int" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "91ebdb8ff6b68e0b93179fae022213185a450649", +// "ObjectID": "a8ada09dee16d791fd406d629fe29bb0ed084a30:4" +// } +// } +// } +// } +// ] +// } diff --git a/contracts/filetest/recover6_filetest.gno b/contracts/filetest/recover6_filetest.gno new file mode 100644 index 00000000000..11186cdb200 --- /dev/null +++ b/contracts/filetest/recover6_filetest.gno @@ -0,0 +1,32 @@ +package main + +import ( + "errors" +) + +func main() { + println(f(false)) + println(f(true)) +} + +func f(dopanic bool) (err error) { + defer func() { + if x := recover(); x != nil { + + err = x.(error) + + } + }() + q(dopanic) + return +} + +func q(dopanic bool) { + if dopanic { + panic(errors.New("wtf")) + } +} + +// Output: +// undefined +// wtf diff --git a/contracts/regression/a17_filetest.gno b/contracts/regression/a17_filetest.gno new file mode 100644 index 00000000000..90b4d4384d3 --- /dev/null +++ b/contracts/regression/a17_filetest.gno @@ -0,0 +1,11 @@ +package main + +import "fmt" + +func main() { + a := make([]int, 2, 7) + fmt.Println(a, len(a), cap(a)) +} + +// Output: +// [0 0] 2 7 diff --git a/contracts/regression/assginInterface_filetest.gno b/contracts/regression/assginInterface_filetest.gno new file mode 100644 index 00000000000..0712cf1e1c6 --- /dev/null +++ b/contracts/regression/assginInterface_filetest.gno @@ -0,0 +1,40 @@ +package main + +type Foo interface { + Len() int +} + +type myIntSlice []int + +func (s myIntSlice) Len() int { + return len(s) +} + +func main() { + var a Foo + var b interface{ Len() int } + + var i myIntSlice + + println(a) + + i = myIntSlice{1} + a = i + + println(a) + + b = interface{ Len() int }(a) + + a = b + + println(a) + + println(b) + +} + +// Output: +// (undefined) +// (slice[(1 int)] main.myIntSlice) +// (slice[(1 int)] main.myIntSlice) +// (slice[(1 int)] main.myIntSlice) diff --git a/contracts/regression/assgin_temp_filetest.gno b/contracts/regression/assgin_temp_filetest.gno new file mode 100644 index 00000000000..c4c7c7b0c32 --- /dev/null +++ b/contracts/regression/assgin_temp_filetest.gno @@ -0,0 +1,14 @@ +package main + +func main() { + var n1 []int + // transcribe n1 = []int{0} to tmp:= []int{0}, n1=temp + // n1 = []int{0} + tmp := []int{0} + n1 = tmp + + println(n1) +} + +// Output: +// slice[(0 int)] diff --git a/contracts/regression/avl1_filetest.gno b/contracts/regression/avl1_filetest.gno new file mode 100644 index 00000000000..aea098ab621 --- /dev/null +++ b/contracts/regression/avl1_filetest.gno @@ -0,0 +1,17 @@ +package main + +import "gno.land/p/demo/avl" + +type String string + +func main() { + tree := avl.Tree{} + key := "key" + _ = tree.Set(key, key) + // + y, z := tree.Get(key) + println(y, z) +} + +// Output: +// key true diff --git a/contracts/regression/errors2_filetest.gno b/contracts/regression/errors2_filetest.gno new file mode 100644 index 00000000000..2588b904a77 --- /dev/null +++ b/contracts/regression/errors2_filetest.gno @@ -0,0 +1,17 @@ +package main + +import "errors" + +func makeError() error { + return errors.New("some error") +} + +func main() { + var a error + a = makeError() + b := a.Error() + println(a) +} + +// Output: +// some error diff --git a/contracts/regression/errors_filetest.gno b/contracts/regression/errors_filetest.gno new file mode 100644 index 00000000000..fb4e8f67eaa --- /dev/null +++ b/contracts/regression/errors_filetest.gno @@ -0,0 +1,14 @@ +package main + +import "errors" + +func makeError() error { + return errors.New("some error") +} + +func main() { + println(makeError()) +} + +// Output: +// some error diff --git a/contracts/regression/return_interface1_filetest.gno b/contracts/regression/return_interface1_filetest.gno new file mode 100644 index 00000000000..625951ff106 --- /dev/null +++ b/contracts/regression/return_interface1_filetest.gno @@ -0,0 +1,16 @@ +package main + +func x1() interface{} { + a := "1" + return a +} + +func main() { + var a uint + a = x1() // should fail + println("1") + +} + +// Error: +// main/contracts/regression/return_interface1_filetest.gno:10: cannot use interface{} as uint diff --git a/contracts/regression/return_interface1a_filetest.gno b/contracts/regression/return_interface1a_filetest.gno new file mode 100644 index 00000000000..3229a5a259a --- /dev/null +++ b/contracts/regression/return_interface1a_filetest.gno @@ -0,0 +1,21 @@ +package main + +// with the first parameter string. it is ok +// with either parameter is string, not ok +func x() (interface{}, string) { + a := "0" + b := "1" + return a, b +} + +func main() { + var a string + var b string + a, b = x() // should fail + println(a) + println(b) + +} + +// Error: +// main/contracts/regression/return_interface1a_filetest.gno:14: cannot use interface{} as string diff --git a/contracts/regression/return_interface_filetest.gno b/contracts/regression/return_interface_filetest.gno new file mode 100644 index 00000000000..db4cc5ec3b8 --- /dev/null +++ b/contracts/regression/return_interface_filetest.gno @@ -0,0 +1,17 @@ +package main + +func x() (interface{}, interface{}) { + a := 0 + return a, a +} + +func main() { + var a, b int + a, b = x() // should have failed LINE 10 + println(a) + println(b) + +} + +// Error: +// main/contracts/regression/return_interface_filetest.gno:10: cannot use interface{} as int diff --git a/contracts/regression/return_two1d_filetest.gno b/contracts/regression/return_two1d_filetest.gno new file mode 100644 index 00000000000..379696f42a5 --- /dev/null +++ b/contracts/regression/return_two1d_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() (interface{}, nat) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + var a nat + var b []int + a, b = x() // This should have failed. + println(a) + println(b) + +} + +// Output diff --git a/contracts/regression/return_two1e_filetest.gno b/contracts/regression/return_two1e_filetest.gno new file mode 100644 index 00000000000..991b76bd7d3 --- /dev/null +++ b/contracts/regression/return_two1e_filetest.gno @@ -0,0 +1,22 @@ +package main + +type nat []int + +func x() (interface{}, interface{}) { + a := nat{0} + + return a, a +} + +func main() { + var a, b nat + + a, b = x() // This should fail + + println(a) + println(b) + +} + +// Error: +// main/contracts/regression/return_two1e_filetest.gno:14: cannot use interface{} as []int diff --git a/contracts/regression/return_two2_filetest.gno b/contracts/regression/return_two2_filetest.gno new file mode 100644 index 00000000000..898db93da01 --- /dev/null +++ b/contracts/regression/return_two2_filetest.gno @@ -0,0 +1,45 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{0} + b := []int{1} + c := nat{2} + return a, b +} + +func main() { + var n1, n2 nat + var u1, u2 []int + var a, b int + + n1, n2 = x() + println(n1) + println(n2) + //println(n3) + + u1, u2 = x() + println(u1) + println(u2) + + n1, u2 = x() + println(n1) + println(u2) + + n2, u1 = x() + + println(n2) + println(u1) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(1 int)] main.nat) +// slice[(0 int)] +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/regression/return_two2a_filetest.gno b/contracts/regression/return_two2a_filetest.gno new file mode 100644 index 00000000000..b03b6d7dce7 --- /dev/null +++ b/contracts/regression/return_two2a_filetest.gno @@ -0,0 +1,31 @@ +package main + +type nat []int + +func x1() nat { + a := nat{0} + + return a +} +func x2() []int { + + b := []int{1} + return b +} + +func main() { + var n2 nat + var u1 []int + + n2 = x2() + + println(n2) + + u1 = x1() + println(u1) + +} + +// Output: +// (slice[(1 int)] main.nat) +// slice[(0 int)] diff --git a/contracts/regression/return_two2b_filetest.gno b/contracts/regression/return_two2b_filetest.gno new file mode 100644 index 00000000000..91142260dc6 --- /dev/null +++ b/contracts/regression/return_two2b_filetest.gno @@ -0,0 +1,44 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + var n1, n2 nat + var u1, u2 []int + + tmp1, tmp2 := x() + n1, n2 = tmp1, tmp2 + println(n1) + println(n2) + + tmp3, tmp4 := x() + u1, u2 = tmp3, tmp4 + println(u1) + println(u2) + + n1, u2 = x() + println(n1) + println(u2) + + n2, u1 = x() + + println(n2) + println(u1) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(1 int)] main.nat) +// slice[(0 int)] +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(0 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/regression/return_two2c_filetest.gno b/contracts/regression/return_two2c_filetest.gno new file mode 100644 index 00000000000..b2f8840e7f0 --- /dev/null +++ b/contracts/regression/return_two2c_filetest.gno @@ -0,0 +1,26 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{1} + b := []int{2} + return a, b +} + +func main() { + var u1 []int + var n2 nat + + u1, n2 = x() + // _tmp_1, _tmp_2 := x() + // u1, n2 = _tmp_1, _tmp_2 + + println(u1) + println(n2) + +} + +// Output: +// slice[(1 int)] +// (slice[(2 int)] main.nat) diff --git a/contracts/return/assgin_interface_filetest.gno b/contracts/return/assgin_interface_filetest.gno new file mode 100644 index 00000000000..129eb8d749a --- /dev/null +++ b/contracts/return/assgin_interface_filetest.gno @@ -0,0 +1,14 @@ +package main + +type nat []int + +func main() { + var a nat + b := interface{}(nat{1}) + a = b.(nat) + + println(b) +} + +// Output: +// (slice[(1 int)] main.nat) diff --git a/contracts/return/assgin_two_filetest.gno b/contracts/return/assgin_two_filetest.gno new file mode 100644 index 00000000000..eadb47f4f12 --- /dev/null +++ b/contracts/return/assgin_two_filetest.gno @@ -0,0 +1,16 @@ +package main + +type nat []int +type nat2 []int + +func main() { + a := nat{0} + b := nat2{1} + a = b + + println(a) + println(b) +} + +// Error: +// main/contracts/return/assgin_two_filetest.gno:9: cannot use main.nat2 as main.nat without explicit conversion diff --git a/contracts/return/return_interface_filetest.gno b/contracts/return/return_interface_filetest.gno new file mode 100644 index 00000000000..b8ee0b58997 --- /dev/null +++ b/contracts/return/return_interface_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() interface{} { + a := nat{0} + return a +} + +func main() { + var a nat + + a = x() + + println(a) + +} + +// Error: +// main/contracts/return/return_interface_filetest.gno:13: cannot use interface{} as []int diff --git a/contracts/return/return_select_filetest.gno b/contracts/return/return_select_filetest.gno new file mode 100644 index 00000000000..3f19e25caf5 --- /dev/null +++ b/contracts/return/return_select_filetest.gno @@ -0,0 +1,28 @@ +package main + +type nat []int + +func x() interface{} { + a := nat{0} + return a +} + +func (n nat) double() nat { + + m := append(n, n...) + return m + +} + +func main() { + a := x() + + b := a.(nat).double().double() + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(0 int),(0 int),(0 int),(0 int)] main.nat) diff --git a/contracts/return/return_two0_filetest.gno b/contracts/return/return_two0_filetest.gno new file mode 100644 index 00000000000..7ea5c3cd7d1 --- /dev/null +++ b/contracts/return/return_two0_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() ([]int, nat) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + a, b := x() + println(a) + println(b) + +} + +// Output: +// slice[(0 int)] +// (slice[(1 int)] main.nat) diff --git a/contracts/return/return_two0b_filetest.gno b/contracts/return/return_two0b_filetest.gno new file mode 100644 index 00000000000..1598ead5c2b --- /dev/null +++ b/contracts/return/return_two0b_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + a, b := x() + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/return/return_two0c_filetest.gno b/contracts/return/return_two0c_filetest.gno new file mode 100644 index 00000000000..02a8a594fa2 --- /dev/null +++ b/contracts/return/return_two0c_filetest.gno @@ -0,0 +1,22 @@ +package main + +type nat []int + +func x() (nat, []int) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + var a nat + var b []int + a, b = x() + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/return/return_two1_filetest.gno b/contracts/return/return_two1_filetest.gno new file mode 100644 index 00000000000..e18ff56e70c --- /dev/null +++ b/contracts/return/return_two1_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() (interface{}, interface{}) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + a, b := x() + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] diff --git a/contracts/return/return_two1b_filetest.gno b/contracts/return/return_two1b_filetest.gno new file mode 100644 index 00000000000..c6dfb4122ee --- /dev/null +++ b/contracts/return/return_two1b_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() ([]int, interface{}) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + a, b := x() + println(a) + println(b) + +} + +// Output: +// slice[(0 int)] +// slice[(1 int)] diff --git a/contracts/return/return_two1c_filetest.gno b/contracts/return/return_two1c_filetest.gno new file mode 100644 index 00000000000..75419f65151 --- /dev/null +++ b/contracts/return/return_two1c_filetest.gno @@ -0,0 +1,20 @@ +package main + +type nat []int + +func x() (interface{}, nat) { + a := nat{0} + b := []int{1} + return a, b +} + +func main() { + a, b := x() + println(a) + println(b) + +} + +// Output: +// (slice[(0 int)] main.nat) +// (slice[(1 int)] main.nat) diff --git a/contracts/stack/poppush_filetest.gno b/contracts/stack/poppush_filetest.gno new file mode 100644 index 00000000000..82ade789398 --- /dev/null +++ b/contracts/stack/poppush_filetest.gno @@ -0,0 +1,34 @@ +package main + +import ( + "strconv" + "strings" +) + +func main() { + Pop() + Push() + println(Render("")) + +} + +var slice = []string{"undead-element"} + +func Pop() { + slice = slice[:len(slice)-1] +} + +func Push() { + slice = append(slice, "new-element") +} + +func Render(path string) string { + str := strings.Join(slice, ", ") + "\n\n" + str += "len: " + strconv.Itoa(len(slice)) + "\n\n" + return str +} + +// Output: +// new-element +// +// len: 1 diff --git a/examples/gno.land/r/demo/tests/realm_compositelit.gno b/examples/gno.land/r/demo/tests/realm_compositelit.gno new file mode 100644 index 00000000000..b7363362314 --- /dev/null +++ b/examples/gno.land/r/demo/tests/realm_compositelit.gno @@ -0,0 +1,21 @@ +package tests + +type Word uint +type nat []Word + +var zero = &Int{ + neg: true, + abs: []Word{0}, +} + +// structLit +type Int struct { + neg bool + abs nat +} + +func GetZeroType() nat { + + a := zero.abs + return a +} diff --git a/examples/gno.land/r/demo/tests/realm_method38d.gno b/examples/gno.land/r/demo/tests/realm_method38d.gno new file mode 100644 index 00000000000..7355efd157c --- /dev/null +++ b/examples/gno.land/r/demo/tests/realm_method38d.gno @@ -0,0 +1,22 @@ +package tests + +var abs nat + +func (n nat) Add() nat { + + return []Word{0} +} + +func GetAbs() nat { + + abs = []Word{0} + + return abs +} + +func AbsAdd() nat { + + rt := GetAbs().Add() + + return rt +} diff --git a/gnovm/pkg/gnolang/nodes.go b/gnovm/pkg/gnolang/nodes.go index e838ba562c0..786b6a15004 100644 --- a/gnovm/pkg/gnolang/nodes.go +++ b/gnovm/pkg/gnolang/nodes.go @@ -668,6 +668,12 @@ func (ss Body) GetBody() Body { return ss } +func (ss *Body) SetBody( nb Body){ + + *ss = nb + +} + func (ss Body) GetLabeledStmt(label Name) (stmt Stmt, idx int) { for idx, stmt = range ss { if label == stmt.GetLabel() { @@ -1331,6 +1337,14 @@ func (x *PackageNode) PrepareNewValues(pv *PackageValue) []TypedValue { panic("PackageNode.PrepareNewValues() package mismatch") } } + // the FuncValue Body maybe be altered during the preprocessing. + // We need to update body field from the source in the FuncValue accordingly. + for _, tv := range x.Values { + + if fv, ok := tv.V.(*FuncValue); ok { + fv.UpdateBodyFromSource() + } + } pvl := len(block.Values) pnl := len(x.Values) // copy new top-level defined values/types. @@ -1435,6 +1449,7 @@ type BlockNode interface { Define(Name, TypedValue) Define2(bool, Name, Type, TypedValue) GetBody() Body + SetBody(Body) } // ---------------------------------------- @@ -1796,18 +1811,39 @@ func (x *IfStmt) GetBody() Body { panic("IfStmt has no body (but .Then and .Else do)") } +func (x *IfStmt) SetBody(b Body) { + + panic("IfStmt has no body (but .Then and .Else do)") +} + func (x *SwitchStmt) GetBody() Body { panic("SwitchStmt has no body (but its cases do)") } +func (x *SwitchStmt) SetBody(b Body) { + + panic("SwitchStmt has no body (but .Then and .Else do)") +} + + func (x *FileNode) GetBody() Body { panic("FileNode has no body (but it does have .Decls)") } +func (x *FileNode) SetBody(b Body) { + + panic("FileNode has no body (but .Then and .Else do)") +} + func (x *PackageNode) GetBody() Body { panic("PackageNode has no body") } +func (x *PackageNode) SetBody(b Body) { + + panic("PackageNode has no body") +} + // ---------------------------------------- // Value Path diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index e02a158fcf1..4e7994c40a4 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1538,8 +1538,13 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { lhs0 := n.Lhs[0].(*NameExpr).Name lhs1 := n.Lhs[1].(*NameExpr).Name - dt := evalStaticTypeOf(store, last, cx.X) - mt := baseOf(dt).(*MapType) + var mt *MapType + st := evalStaticTypeOf(store, last, cx.X) + if dt, ok := st.(*DeclaredType); ok { + mt = dt.Base.(*MapType) + } else if mt, ok = st.(*MapType); !ok { + panic("should not happen") + } // re-definitions last.Define(lhs0, anyValue(mt.Value)) last.Define(lhs1, anyValue(BoolType)) @@ -1580,6 +1585,83 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { "%d variables but %s returns %d values", len(n.Lhs), cx.Func.String(), len(cft.Results))) } + // check if we we need to decompose for named typed conversion in the function return results + decompose := false + + for i, rhsType := range cft.Results { + lt := evalStaticTypeOf(store, last, n.Lhs[i]) + if lt != nil && isNamedConversion(rhsType.Type, lt) { + decompose = true + break + } + } + + if decompose ==true{ + + + // only enter this section if cft.Results to be converted to Lhs type for named type conversion. + // decompose a,b = x() + // tmp1, tmp2 := x() assignment statemet expression (Op=DEFINE) + // a,b = tmp1, tmp2 assignment statemet expression ( Op=ASSIGN ) + // add the new statement to last.Body + + // step1: + // create a hidden var with leading _ the curBodyLen increase every time when there is an decompostion + // because there could be multiple decomposition happens + // we use both stmt index and resturn result number to differentiate the _tmp variables created in each assignment decompostion + // ex. _tmp_3_2: this variabl is created as the 3rd statement in the block, the 2nd parameter returned from x(), + // create _tmp_1_1, tmp_1_2 .... based on number of result from x() + var tmpExprs Exprs + for i, _ := range cft.Results { + rn := fmt.Sprintf("_tmp_%d_%d", index, i) + tmpExprs = append(tmpExprs, Nx(rn)) + } + // step2: + // tmp1, tmp2 := x() + dsx := &AssignStmt{ + Lhs: tmpExprs, + Op: DEFINE, + Rhs: n.Rhs, + } + dsx.SetLine(n.Line) + dsx = Preprocess(store, last,dsx).(*AssignStmt) + + // step3: + + // a,b = tmp1, tmp2 + // assign stmt expression + // the right hand side will be converted to call expr for nameed/unnamed covnerstion + // we make a copy of tmpExrs to prevent dsx.Lhs in the preview statement changing by the side effect + // when asx.Rhs is converted to const call expr during the preprocess of the next statement + + asx := &AssignStmt{ + Lhs: n.Lhs, + Op: ASSIGN, + Rhs: copyExprs(tmpExprs), + + } + asx.SetLine(n.Line) + asx = Preprocess(store, last,asx).(*AssignStmt) + + // step4: + // replace the orignal stmt with two new stmts + body := last.GetBody() + // we need to do an in-place replacement while leaving the current node + n.Attributes = dsx.Attributes + n.Lhs = dsx.Lhs + n.Op =dsx.Op + n.Rhs=dsx.Rhs + + // insert a assignment statement a,b = tmp1,tmp2 AFTER the current statement in the last.Body. + body = append(body[:index+1], append(Body{asx}, body[index+1:]...)...) + last.SetBody(body) + } // end of the decomposition + + // DISCUSSION: we need to insert the statements to FuncValue.body of PackageNopde.Values[i].V + // Option1: make FuncValue.body as a poninter to FuncValue.Source.Body + // Option2: updating FuncValue.body=FuncValue.Source.Body in updates := pn.PrepareNewValues(pv) during preprocess. + // current is Option2. we need to Update FuncValue from source + // Option3: in Op_Call: FuncValue.GetBodyFromSource synce FuncValue.body with Source body case *TypeAssertExpr: // Type-assert case: a, ok := x.(type) if len(n.Lhs) != 2 { @@ -2146,12 +2228,12 @@ func getResultTypedValues(cx *CallExpr) []TypedValue { func evalConst(store Store, last BlockNode, x Expr) *ConstExpr { // TODO: some check or verification for ensuring x // is constant? From the machine? - cv := NewMachine(".dontcare", store) - tv := cv.EvalStatic(last, x) - cv.Release() + m := NewMachine(".dontcare", store) + cv := m.EvalStatic(last, x) + m.Release() cx := &ConstExpr{ Source: x, - TypedValue: tv, + TypedValue: cv, } cx.SetAttribute(ATTR_PREPROCESSED, true) setConstAttrs(cx) @@ -2308,11 +2390,13 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative // "push" expected type into shift binary's left operand. checkOrConvertType(store, last, &bx.Left, t, autoNative) } else if *x != nil { // XXX if x != nil && t != nil { + // check type xt := evalStaticTypeOf(store, last, *x) if t != nil { checkType(xt, t, autoNative) } - if isUntyped(xt) { + // convert type + if isUntyped(xt) { // convert if x is untyped literal if t == nil { t = defaultTypeOf(xt) } @@ -2333,11 +2417,54 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative // default: } } + // convert x to destination type t cx := Expr(Call(constType(nil, t), *x)) cx = Preprocess(store, last, cx).(Expr) *x = cx + } else { + //if one side is declared name type and the other side is unnamed type + if isNamedConversion(xt, t) { + // covert right (xt) to the type of the left (t) + cx := Expr(Call(constType(nil, t), *x)) + cx = Preprocess(store, last, cx).(Expr) + *x = cx + } + } + } +} + +// Return true if we need to convert named and unnamed types in an assignment +func isNamedConversion(xt, t Type) bool { + + if t == nil { + + t = xt + } + + // t is left hand destination type, xt is right hand expression type + // In a few special cases, we should not consider compare named and unnamed type + // case 1: if left is interface, which is unnamed, we dont convert to the left type even right is named type. + + _, c1 := t.(*InterfaceType) + + // case2: TypeType is used in make() new() native uverse definition and TypeType.IsNamed() will panic on unexpected. + + _, oktt := t.(*TypeType) + _, oktt2 := xt.(*TypeType) + c2 := oktt || oktt2 + + // + if !c1 && !c2 { // carve out above two cases + // covert right to the type of left if one side is unnamed type and the other side is not + + if t.IsNamed() && !xt.IsNamed() || + !t.IsNamed() && xt.IsNamed() { + return true } + } + return false + } // like checkOrConvertType(last, x, nil) diff --git a/gnovm/pkg/gnolang/transcribe.go b/gnovm/pkg/gnolang/transcribe.go index c5b72336c83..94f933c05d1 100644 --- a/gnovm/pkg/gnolang/transcribe.go +++ b/gnovm/pkg/gnolang/transcribe.go @@ -271,7 +271,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc } else { cnn = cnn2.(*FuncLitExpr) } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_FUNCLIT_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -383,7 +383,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc } else { cnn = cnn2.(*BlockStmt) } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_BLOCK_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -393,7 +393,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc } case *BranchStmt: case *DeclStmt: - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_DECL_BODY, idx, cnn.Body[idx], &c).(SimpleDeclStmt) if isBreak(c) { break @@ -438,7 +438,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc return } } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_FOR_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -488,7 +488,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc } else { cnn = cnn2.(*IfCaseStmt) } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_IF_CASE_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -525,7 +525,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc return } } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_RANGE_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -565,7 +565,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc if isStopOrSkip(nc, c) { return } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_SELECTCASE_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -640,7 +640,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc return } } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_SWITCHCASE_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break @@ -666,7 +666,7 @@ func transcribe(t Transform, ns []Node, ftype TransField, index int, n Node, nc } else { cnn = cnn2.(*FuncDecl) } - for idx := range cnn.Body { + for idx := 0; idx < len(cnn.Body); idx++ { // the len of Body could change when we decompose a statemet to mulitiple statments. cnn.Body[idx] = transcribe(t, nns, TRANS_FUNC_BODY, idx, cnn.Body[idx], &c).(Stmt) if isBreak(c) { break diff --git a/gnovm/pkg/gnolang/types.go b/gnovm/pkg/gnolang/types.go index c3e439e9427..d092b89e4db 100644 --- a/gnovm/pkg/gnolang/types.go +++ b/gnovm/pkg/gnolang/types.go @@ -24,6 +24,7 @@ type Type interface { String() string // for dev/debugging Elem() Type // for TODO... types GetPkgPath() string + IsNamed() bool // named vs unname type. property as a method } type TypeID string @@ -323,6 +324,10 @@ func (pt PrimitiveType) GetPkgPath() string { return "" } +func (pt PrimitiveType) IsNamed() bool { + return true +} + // ---------------------------------------- // Field type (partial) @@ -369,6 +374,10 @@ func (ft FieldType) GetPkgPath() string { panic("FieldType is a pseudotype with no package path") } +func (ft FieldType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // FieldTypeList @@ -528,6 +537,10 @@ func (at *ArrayType) GetPkgPath() string { return "" } +func (at *ArrayType) IsNamed() bool { + return false +} + // ---------------------------------------- // Slice type @@ -574,6 +587,10 @@ func (st *SliceType) GetPkgPath() string { return "" } +func (st *SliceType) IsNamed() bool { + return false +} + // ---------------------------------------- // Pointer type @@ -612,6 +629,10 @@ func (pt *PointerType) GetPkgPath() string { return pt.Elt.GetPkgPath() } +func (pt *PointerType) IsNamed() bool { + return false +} + func (pt *PointerType) FindEmbeddedFieldType(callerPath string, n Name, m map[Type]struct{}) ( trail []ValuePath, hasPtr bool, rcvr Type, field Type, accessError bool, ) { @@ -747,6 +768,10 @@ func (st *StructType) GetPkgPath() string { return st.PkgPath } +func (st *StructType) IsNamed() bool { + return false +} + // NOTE only works for exposed non-embedded fields. func (st *StructType) GetPathForName(n Name) ValuePath { for i := 0; i < len(st.Fields); i++ { @@ -867,6 +892,10 @@ func (pt *PackageType) GetPkgPath() string { panic("package types has no package path (unlike package values)") } +func (pt *PackageType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // Interface type @@ -927,6 +956,10 @@ func (it *InterfaceType) GetPkgPath() string { return it.PkgPath } +func (it *InterfaceType) IsNamed() bool { + return false +} + func (it *InterfaceType) FindEmbeddedFieldType(callerPath string, n Name, m map[Type]struct{}) ( trail []ValuePath, hasPtr bool, rcvr Type, ft Type, accessError bool, ) { @@ -1074,6 +1107,10 @@ func (ct *ChanType) GetPkgPath() string { return "" } +func (ct *ChanType) IsNamed() bool { + return false +} + // ---------------------------------------- // Function type @@ -1275,6 +1312,9 @@ func (ft *FuncType) GetPkgPath() string { panic("function types have no package path") } +func (ft *FuncType) IsNamed() bool { + return false +} func (ft *FuncType) HasVarg() bool { if numParams := len(ft.Params); numParams == 0 { return false @@ -1333,6 +1373,10 @@ func (mt *MapType) GetPkgPath() string { return "" } +func (mt *MapType) IsNamed() bool { + return false +} + // ---------------------------------------- // Type (typeval) type @@ -1361,6 +1405,10 @@ func (tt *TypeType) GetPkgPath() string { panic("typeval types have no package path") } +func (tt *TypeType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // Declared type // Declared types have a name, base (underlying) type, @@ -1445,6 +1493,10 @@ func (dt *DeclaredType) GetPkgPath() string { return dt.PkgPath } +func (dt *DeclaredType) IsNamed() bool { + return true +} + func (dt *DeclaredType) DefineMethod(fv *FuncValue) { dt.Methods = append(dt.Methods, TypedValue{ T: fv.Type, @@ -1711,6 +1763,14 @@ func (nt *NativeType) GetPkgPath() string { return "go:" + nt.Type.PkgPath() } +func (nt *NativeType) IsNamed() bool { + if nt.Type.Name() != "" { + return true + } else { + return false + } +} + func (nt *NativeType) GnoType(store Store) Type { if nt.gnoType == nil { nt.gnoType = store.Go2GnoType(nt.Type) @@ -1839,6 +1899,10 @@ func (bt blockType) GetPkgPath() string { panic("blockType has no package path") } +func (bt blockType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // tupleType @@ -1889,6 +1953,10 @@ func (tt *tupleType) GetPkgPath() string { panic("typleType has no package path") } +func (tt *tupleType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // RefType @@ -1916,6 +1984,10 @@ func (rt RefType) GetPkgPath() string { panic("should not happen") } +func (rt RefType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // MaybeNativeType @@ -1946,6 +2018,10 @@ func (mn MaybeNativeType) GetPkgPath() string { return mn.Type.GetPkgPath() } +func (mn MaybeNativeType) IsNamed() bool { + return mn.IsNamed() +} + // ---------------------------------------- // Kind diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 495fcf74cb7..5e1a8308c55 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -568,6 +568,15 @@ func (fv *FuncValue) GetBodyFromSource(store Store) []Stmt { return fv.body } +func (fv *FuncValue) UpdateBodyFromSource() { + if fv.Source == nil { + panic(fmt.Sprintf( + "Source is missing for FuncValue %s", + fv.Name)) + } + fv.body = fv.Source.GetBody() +} + func (fv *FuncValue) GetSource(store Store) BlockNode { if rn, ok := fv.Source.(RefNode); ok { source := store.GetBlockNode(rn.GetLocation()) diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index 4819c2064e8..855d8f04b37 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -176,6 +176,9 @@ func (tv *TypedValue) Sprint(m *Machine) string { res := m.Eval(Call(Sel(&ConstExpr{TypedValue: *tv}, "Error"))) return res[0].GetString() } + if _, ok := tv.T.(*DeclaredType); ok { + return tv.String() + } // otherwise, default behavior. switch bt := baseOf(tv.T).(type) { case PrimitiveType: @@ -223,11 +226,29 @@ func (tv *TypedValue) Sprint(m *Machine) string { case *ArrayType: return tv.V.(*ArrayValue).String() case *SliceType: - return tv.V.(*SliceValue).String() + switch sv := tv.V.(type) { + case nil: + return tv.String() + case *SliceValue: + return sv.String() + default: + panic(fmt.Sprintf( + "unexpected slice type %v", + reflect.TypeOf(tv.V))) + } case *StructType: return tv.V.(*StructValue).String() case *MapType: - return tv.V.(*MapValue).String() + switch mv := tv.V.(type) { + case nil: + return tv.String() + case *MapValue: + return mv.String() + default: + panic(fmt.Sprintf( + "unexpected slice type %v", + reflect.TypeOf(tv.V))) + } case *FuncType: switch fv := tv.V.(type) { case nil: diff --git a/gnovm/tests/files/addr0b_stdlibs.gno b/gnovm/tests/files/addr0b_stdlibs.gno index e2848c2321b..2ec6782c7f0 100644 --- a/gnovm/tests/files/addr0b_stdlibs.gno +++ b/gnovm/tests/files/addr0b_stdlibs.gno @@ -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) diff --git a/gnovm/tests/files/assign21.gno b/gnovm/tests/files/assign21.gno index 9d3595e95bd..c24d902c0c0 100644 --- a/gnovm/tests/files/assign21.gno +++ b/gnovm/tests/files/assign21.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// 1 true +// (1 main.thing) true diff --git a/gnovm/tests/files/composite2.gno b/gnovm/tests/files/composite2.gno index 5e8dc6afc1b..e6882e03b8b 100644 --- a/gnovm/tests/files/composite2.gno +++ b/gnovm/tests/files/composite2.gno @@ -9,4 +9,4 @@ func main() { } // Output: -// struct{("hello" string)} +// (struct{("hello" string)} main.T) diff --git a/gnovm/tests/files/composite5.gno b/gnovm/tests/files/composite5.gno index 15c4aa530e7..906f9d4f930 100644 --- a/gnovm/tests/files/composite5.gno +++ b/gnovm/tests/files/composite5.gno @@ -11,4 +11,4 @@ func main() { } // Output: -// struct{(12 uint16)} +// (struct{(12 uint16)} main.T) diff --git a/gnovm/tests/files/composite6.gno b/gnovm/tests/files/composite6.gno index 122665aa9d7..25817cde400 100644 --- a/gnovm/tests/files/composite6.gno +++ b/gnovm/tests/files/composite6.gno @@ -15,4 +15,4 @@ func main() { } // Output: -// struct{(2 uint16)} +// (struct{(2 uint16)} main.T) diff --git a/gnovm/tests/files/const12.gno b/gnovm/tests/files/const12.gno index 84510bf16b5..86dde62eb3d 100644 --- a/gnovm/tests/files/const12.gno +++ b/gnovm/tests/files/const12.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// 0 2 4 6 +// (0 main.Kind) (2 main.Kind) (4 main.Kind) (6 main.Kind) diff --git a/gnovm/tests/files/const15.gno b/gnovm/tests/files/const15.gno index ed55754726c..a2af6c6a849 100644 --- a/gnovm/tests/files/const15.gno +++ b/gnovm/tests/files/const15.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// 3 +// (3 main.T1) diff --git a/gnovm/tests/files/fun6b.gno b/gnovm/tests/files/fun6b.gno index 9ff57036333..17b0473b33b 100644 --- a/gnovm/tests/files/fun6b.gno +++ b/gnovm/tests/files/fun6b.gno @@ -17,4 +17,4 @@ func main() { } // Output: -// struct{(gonative{} gonative{*sync.Pool})} +// (struct{(gonative{} gonative{*sync.Pool})} main.Pool) diff --git a/gnovm/tests/files/fun9.gno b/gnovm/tests/files/fun9.gno index 5b5ec1bfe36..18c49a3a226 100644 --- a/gnovm/tests/files/fun9.gno +++ b/gnovm/tests/files/fun9.gno @@ -9,4 +9,4 @@ func main() { } // Output: -// 1 +// (1 main.myint) diff --git a/gnovm/tests/files/interface39b.gno b/gnovm/tests/files/interface39b.gno index 9a49c0abdef..a87b9ff1d30 100644 --- a/gnovm/tests/files/interface39b.gno +++ b/gnovm/tests/files/interface39b.gno @@ -18,4 +18,4 @@ func main() { } // Output: -// struct{("bar" string)} +// (struct{("bar" string)} main.foo) diff --git a/gnovm/tests/files/map19b.gno b/gnovm/tests/files/map19b.gno index dbbb6876cc6..77361016591 100644 --- a/gnovm/tests/files/map19b.gno +++ b/gnovm/tests/files/map19b.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// struct{(nil map[int64]*main.server)} +// (struct{(nil map[int64]*main.server)} main.cmap) diff --git a/gnovm/tests/files/ptr0.gno b/gnovm/tests/files/ptr0.gno index 2c61280b2ee..dd459e2d29f 100644 --- a/gnovm/tests/files/ptr0.gno +++ b/gnovm/tests/files/ptr0.gno @@ -9,4 +9,4 @@ func main() { } // Output: -// 2 +// (2 main.myint) diff --git a/gnovm/tests/files/ptr7.gno b/gnovm/tests/files/ptr7.gno index 1c6d7ae4040..b8f7fc9cf88 100644 --- a/gnovm/tests/files/ptr7.gno +++ b/gnovm/tests/files/ptr7.gno @@ -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) diff --git a/gnovm/tests/files/recurse0.gno b/gnovm/tests/files/recurse0.gno index 2bf8f539f5a..fe5a997b19f 100644 --- a/gnovm/tests/files/recurse0.gno +++ b/gnovm/tests/files/recurse0.gno @@ -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) diff --git a/gnovm/tests/files/struct28b.gno b/gnovm/tests/files/struct28b.gno index dc61b00bb6f..e426fe490e2 100644 --- a/gnovm/tests/files/struct28b.gno +++ b/gnovm/tests/files/struct28b.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// struct{(struct{(nil *main.T1)} main.T2)} +// (struct{(struct{(nil *main.T1)} main.T2)} main.T1) diff --git a/gnovm/tests/files/struct50b.gno b/gnovm/tests/files/struct50b.gno index 62558c5b69f..212238c5cd7 100644 --- a/gnovm/tests/files/struct50b.gno +++ b/gnovm/tests/files/struct50b.gno @@ -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) diff --git a/gnovm/tests/files/struct52b.gno b/gnovm/tests/files/struct52b.gno index 167e45d10a6..f1b26641149 100644 --- a/gnovm/tests/files/struct52b.gno +++ b/gnovm/tests/files/struct52b.gno @@ -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) diff --git a/gnovm/tests/files/struct53b.gno b/gnovm/tests/files/struct53b.gno index b0f9be2659d..a367b109d30 100644 --- a/gnovm/tests/files/struct53b.gno +++ b/gnovm/tests/files/struct53b.gno @@ -18,4 +18,4 @@ func main() { } // Output: -// struct{(nil *main.T)} +// (struct{(nil *main.T)} main.T2) diff --git a/gnovm/tests/files/type0.gno b/gnovm/tests/files/type0.gno index 739cd711f93..38e385a04d9 100644 --- a/gnovm/tests/files/type0.gno +++ b/gnovm/tests/files/type0.gno @@ -8,4 +8,4 @@ func main() { } // Output: -// 0 +// (0 main.newInt) diff --git a/gnovm/tests/files/zrealm10.gno b/gnovm/tests/files/zrealm10.gno index 12925ddd680..97bb9d439e2 100644 --- a/gnovm/tests/files/zrealm10.gno +++ b/gnovm/tests/files/zrealm10.gno @@ -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"] diff --git a/gnovm/tests/files/zrealm11.gno b/gnovm/tests/files/zrealm11.gno index 0f1616db14d..0f4d26a44c0 100644 --- a/gnovm/tests/files/zrealm11.gno +++ b/gnovm/tests/files/zrealm11.gno @@ -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"] diff --git a/gnovm/tests/files/zrealm8.gno b/gnovm/tests/files/zrealm8.gno index e8ca92c8b69..1452301dac6 100644 --- a/gnovm/tests/files/zrealm8.gno +++ b/gnovm/tests/files/zrealm8.gno @@ -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"] diff --git a/gnovm/tests/files/zrealm9.gno b/gnovm/tests/files/zrealm9.gno index 52e2da3565e..306ca02a92a 100644 --- a/gnovm/tests/files/zrealm9.gno +++ b/gnovm/tests/files/zrealm9.gno @@ -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"] diff --git a/gnovm/tests/files/zrealm_crossrealm0.gno b/gnovm/tests/files/zrealm_crossrealm0.gno index 053e2258465..5bf34c2c852 100644 --- a/gnovm/tests/files/zrealm_crossrealm0.gno +++ b/gnovm/tests/files/zrealm_crossrealm0.gno @@ -14,4 +14,4 @@ func main() { } // Output: -// struct{("test" string)} +// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject) diff --git a/gnovm/tests/files/zrealm_crossrealm1.gno b/gnovm/tests/files/zrealm_crossrealm1.gno index 59b2d317b8a..686468b40c7 100644 --- a/gnovm/tests/files/zrealm_crossrealm1.gno +++ b/gnovm/tests/files/zrealm_crossrealm1.gno @@ -17,4 +17,4 @@ func main() { } // Output: -// struct{("test" string)} +// (struct{("test" string)} gno.land/r/demo/tests.TestRealmObject) diff --git a/gnovm/tests/files/zrealm_crossrealm6.gno b/gnovm/tests/files/zrealm_crossrealm6.gno index c17e317f2eb..d2e7a4b096a 100644 --- a/gnovm/tests/files/zrealm_crossrealm6.gno +++ b/gnovm/tests/files/zrealm_crossrealm6.gno @@ -18,4 +18,4 @@ func main() { } // Output: -// struct{("modified" string)} +// (struct{("modified" string)} gno.land/p/demo/tests.TestRealmObject2) diff --git a/gnovm/tests/files/zrealm_std1.gno b/gnovm/tests/files/zrealm_std1.gno index 85391bd26b1..87f75bcb871 100644 --- a/gnovm/tests/files/zrealm_std1.gno +++ b/gnovm/tests/files/zrealm_std1.gno @@ -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 diff --git a/gnovm/tests/files/zrealm_std2.gno b/gnovm/tests/files/zrealm_std2.gno index 68c09a741d8..1ae1fb4a881 100644 --- a/gnovm/tests/files/zrealm_std2.gno +++ b/gnovm/tests/files/zrealm_std2.gno @@ -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 diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 9eaf7fb9a96..6244f391574 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -23,7 +23,7 @@ func main() { // Realm: // switchrealm["gno.land/r/demo/tests"] -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:10]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14]={ // "Fields": [ // { // "T": { @@ -37,13 +37,13 @@ func main() { // } // ], // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:10", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14", // "ModTime": "0", -// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9", +// "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13", // "RefCount": "1" // } // } -// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9]={ +// c[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13]={ // "Data": null, // "List": [ // { @@ -65,8 +65,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "94c14b2efc4bb2f3c24ee42292f161fd1ebd72a3", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" +// "Hash": "63ef2b51ca911a9b1727588bacb958ec3cb2a392", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:10" // } // } // } @@ -90,8 +90,8 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "1e36da78d1dc72e5cbac56c27590332574c89678", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:8" +// "Hash": "54c554e1d1f61e19feb13bb229f43540338c0f8f", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:12" // } // } // } @@ -115,15 +115,15 @@ func main() { // }, // "V": { // "@type": "/gno.RefValue", -// "Hash": "43b13870b750f78cda919fa13a5d955d297242bd", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:10" +// "Hash": "4e50e2cdaeb022a6fcbdb96d9fbd7f3af8df1379", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:14" // } // } // } // } // ], // "ObjectInfo": { -// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9", +// "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13", // "ModTime": "0", // "OwnerID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "RefCount": "1" @@ -134,8 +134,8 @@ func main() { // "ObjectInfo": { // "ID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:2", // "IsEscaped": true, -// "ModTime": "8", -// "RefCount": "3" +// "ModTime": "12", +// "RefCount": "5" // }, // "Parent": null, // "Source": { @@ -199,6 +199,225 @@ func main() { // "Type": { // "@type": "/gno.DeclaredType", // "Base": { +// "@type": "/gno.PrimitiveType", +// "value": "2048" +// }, +// "Methods": [], +// "Name": "Word", +// "PkgPath": "gno.land/r/demo/tests" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.SliceType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.Word" +// }, +// "Vrd": false +// }, +// "Methods": [ +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "n", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "realm_method38d.gno", +// "IsMethod": true, +// "Name": "Add", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "5", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "n", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "n", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": null, +// "FileName": "realm_method38d.gno", +// "IsMethod": true, +// "Name": "Add", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "5", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [ +// { +// "Embedded": false, +// "Name": "n", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// } +// } +// } +// ], +// "Name": "nat", +// "PkgPath": "gno.land/r/demo/tests" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { +// "@type": "/gno.StructType", +// "Fields": [ +// { +// "Embedded": false, +// "Name": "neg", +// "Tag": "", +// "Type": { +// "@type": "/gno.PrimitiveType", +// "value": "4" +// } +// }, +// { +// "Embedded": false, +// "Name": "abs", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ], +// "PkgPath": "gno.land/r/demo/tests" +// }, +// "Methods": [], +// "Name": "Int", +// "PkgPath": "gno.land/r/demo/tests" +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.TypeType" +// }, +// "V": { +// "@type": "/gno.TypeValue", +// "Type": { +// "@type": "/gno.DeclaredType", +// "Base": { // "@type": "/gno.StructType", // "Fields": [ // { @@ -505,7 +724,17 @@ func main() { // "T": { // "@type": "/gno.FuncType", // "Params": [], -// "Results": [] +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] // }, // "V": { // "@type": "/gno.FuncValue", @@ -514,6 +743,158 @@ func main() { // "Escaped": true, // "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" // }, +// "FileName": "realm_compositelit.gno", +// "IsMethod": false, +// "Name": "GetZeroType", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_compositelit.gno", +// "Line": "17", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:5" +// }, +// "FileName": "realm_method38d.gno", +// "IsMethod": false, +// "Name": "GetAbs", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "10", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:5" +// }, +// "FileName": "realm_method38d.gno", +// "IsMethod": false, +// "Name": "AbsAdd", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "17", +// "Nonce": "0", +// "PkgPath": "gno.land/r/demo/tests" +// } +// }, +// "Type": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [ +// { +// "Embedded": false, +// "Name": "", +// "Tag": "", +// "Type": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// } +// ] +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.FuncType", +// "Params": [], +// "Results": [] +// }, +// "V": { +// "@type": "/gno.FuncValue", +// "Closure": { +// "@type": "/gno.RefValue", +// "Escaped": true, +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" +// }, // "FileName": "tests.gno", // "IsMethod": false, // "Name": "IncCounter", @@ -556,7 +937,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -610,7 +991,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -654,7 +1035,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -698,7 +1079,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -755,7 +1136,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -802,7 +1183,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -836,7 +1217,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -870,7 +1251,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -906,8 +1287,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "5e5535af7afef6f523a897c051944639ef56c057", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9" +// "Hash": "5f12a61dd16d828be8584debc0e395e8d2136acb", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13" // }, // "Length": "3", // "Maxcap": "3", @@ -916,6 +1297,37 @@ func main() { // }, // { // "T": { +// "@type": "/gno.PointerType", +// "Elt": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.Int" +// } +// }, +// "V": { +// "@type": "/gno.PointerValue", +// "Base": null, +// "Index": "0", +// "TV": { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.Int" +// }, +// "V": { +// "@type": "/gno.RefValue", +// "Hash": "90b77781ec2b1e153ac020b1102354174bde972e", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:7" +// } +// } +// } +// }, +// { +// "T": { +// "@type": "/gno.RefType", +// "ID": "gno.land/r/demo/tests.nat" +// } +// }, +// { +// "T": { // "@type": "/gno.PrimitiveType", // "value": "32" // } @@ -949,7 +1361,7 @@ func main() { // } // ] // } -// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:7] +// d[0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:11] // switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests_foo"] // switchrealm["gno.land/r/demo/tests_foo"]