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..57c42280c41 --- /dev/null +++ b/examples/gno.land/r/demo/tests/realm_compositelit.gno @@ -0,0 +1,22 @@ +package tests + +type ( + Word uint + 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..b1dbab67e1f --- /dev/null +++ b/examples/gno.land/r/demo/tests/realm_method38d.gno @@ -0,0 +1,19 @@ +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/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 60406099e1c..459910505b9 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1621,8 +1621,12 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { lhs0 := n.Lhs[0].(*NameExpr).Name lhs1 := n.Lhs[1].(*NameExpr).Name + var mt *MapType dt := evalStaticTypeOf(store, last, cx.X) - mt := baseOf(dt).(*MapType) + mt, ok := baseOf(dt).(*MapType) + if !ok { + panic(fmt.Sprintf("invalid index expression on %T", dt)) + } // re-definitions last.Define(lhs0, anyValue(mt.Value)) last.Define(lhs1, anyValue(BoolType)) @@ -2263,12 +2267,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) @@ -2465,11 +2469,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) } @@ -2490,11 +2496,61 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative // default: } } - cx := Expr(Call(constType(nil, t), *x)) - cx = Preprocess(store, last, cx).(Expr) - *x = cx + // convert x to destination type t + convertType(store, last, x, t) + } 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) + convertType(store, last, x, t) + } + } + } +} + +// convert x to destination type t +func convertType(store Store, last BlockNode, x *Expr, t Type) { + cx := Expr(Call(constType(nil, t), *x)) + cx = Preprocess(store, last, cx).(Expr) + *x = cx +} + +// isNamedConversion returns true if assigning a value of type +// xt (rhs) into a value of type t (lhs) entails an implicit type conversion. +// xt is the result of an expression type. +// +// In a few special cases, we should not perform the conversion: +// +// case 1: the LHS is an interface, which is unnamed, so we should not +// convert to that even if right is a named type. +// case 2: isNamedConversion is called within evaluating make() or new() +// (uverse functions). It returns TypType (generic) which does have IsNamed appropriate +func isNamedConversion(xt, t Type) bool { + if t == nil { + t = xt + } + + // no conversion case 1: the LHS is an interface + + _, c1 := t.(*InterfaceType) + + // no conversion case2: isNamedConversion is called within evaluating make() or new() + // (uverse functions) + + _, 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/types.go b/gnovm/pkg/gnolang/types.go index e1814e8f243..fcfcd7d9d37 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("FieldType is a pseudotype with no property called named") +} + // ---------------------------------------- // 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("package types have no property called named") +} + // ---------------------------------------- // Interface type @@ -926,6 +955,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, ) { @@ -1073,6 +1106,10 @@ func (ct *ChanType) GetPkgPath() string { return "" } +func (ct *ChanType) IsNamed() bool { + return false +} + // ---------------------------------------- // Function type @@ -1280,6 +1317,10 @@ 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 @@ -1338,6 +1379,10 @@ func (mt *MapType) GetPkgPath() string { return "" } +func (mt *MapType) IsNamed() bool { + return false +} + // ---------------------------------------- // Type (typeval) type @@ -1366,6 +1411,10 @@ func (tt *TypeType) GetPkgPath() string { panic("typeval types have no package path") } +func (tt *TypeType) IsNamed() bool { + panic("typeval types have no property called 'named'") +} + // ---------------------------------------- // Declared type // Declared types have a name, base (underlying) type, @@ -1450,6 +1499,10 @@ func (dt *DeclaredType) GetPkgPath() string { return dt.PkgPath } +func (dt *DeclaredType) IsNamed() bool { + return true +} + func (dt *DeclaredType) DefineMethod(fv *FuncValue) { if !dt.TryDefineMethod(fv) { panic(fmt.Sprintf("redeclaration of method %s.%s", @@ -1767,6 +1820,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) @@ -1895,6 +1956,10 @@ func (bt blockType) GetPkgPath() string { panic("blockType has no package path") } +func (bt blockType) IsNamed() bool { + panic("blockType has no property called named") +} + // ---------------------------------------- // tupleType @@ -1945,6 +2010,10 @@ func (tt *tupleType) GetPkgPath() string { panic("typleType has no package path") } +func (tt *tupleType) IsNamed() bool { + panic("typleType has no property called named") +} + // ---------------------------------------- // RefType @@ -1965,11 +2034,15 @@ func (rt RefType) String() string { } func (rt RefType) Elem() Type { - panic("should not happen") + panic("RefType has no elem type") } func (rt RefType) GetPkgPath() string { - panic("should not happen") + panic("RefType has no package path") +} + +func (rt RefType) IsNamed() bool { + panic("RefType has no property called named") } // ---------------------------------------- @@ -2002,6 +2075,10 @@ func (mn MaybeNativeType) GetPkgPath() string { return mn.Type.GetPkgPath() } +func (mn MaybeNativeType) IsNamed() bool { + return mn.Type.IsNamed() +} + // ---------------------------------------- // Kind diff --git a/gnovm/pkg/gnolang/uverse_test.go b/gnovm/pkg/gnolang/uverse_test.go index 7280d131ec5..7a6c0567e45 100644 --- a/gnovm/pkg/gnolang/uverse_test.go +++ b/gnovm/pkg/gnolang/uverse_test.go @@ -39,7 +39,7 @@ func TestIssue1337PrintNilSliceAsUndefined(t *testing.T) { var a []string println(a) }`, - expected: "nil []string\n", + expected: "(nil []string)\n", }, { name: "print non-empty slice", @@ -57,7 +57,7 @@ func TestIssue1337PrintNilSliceAsUndefined(t *testing.T) { var a map[string]string println(a) }`, - expected: "nil map[string]string\n", + expected: "(nil map[string]string)\n", }, { name: "print non-empty map", diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index ad6e7bfc854..4ae05c8a97d 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -376,7 +376,7 @@ func (tv *TypedValue) ProtectedSprint(seen *seenValues, considerDeclaredType boo default: // The remaining types may have a nil value. if tv.V == nil { - return nilStr + " " + tv.T.String() + return "(" + nilStr + " " + tv.T.String() + ")" } // *ArrayType, *SliceType, *StructType, *MapType diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 5622892efa1..4313fd88645 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -33,35 +33,14 @@ func TestFiles(t *testing.T) { } func TestChallenges(t *testing.T) { + t.Skip("Challenge tests, skipping.") baseDir := filepath.Join(".", "challenges") runFileTests(t, baseDir, nil) } -func filterFileTests(t *testing.T, files []fs.DirEntry, ignore []string) []fs.DirEntry { - t.Helper() - - for i := 0; i < len(files); i++ { - file := files[i] - skip := func() { files = append(files[:i], files[i+1:]...); i-- } - if filepath.Ext(file.Name()) != ".gno" { - skip() - continue - } - for _, is := range ignore { - if match, err := path.Match(is, file.Name()); match { - skip() - continue - } else if err != nil { - t.Fatalf("error parsing glob pattern %q: %v", is, err) - } - } - if testing.Short() && strings.Contains(file.Name(), "_long") { - t.Logf("skipping test %s in short mode.", file.Name()) - skip() - continue - } - } - return files +type testFile struct { + path string + fs.DirEntry } // ignore are glob patterns to ignore @@ -70,34 +49,84 @@ func runFileTests(t *testing.T, baseDir string, ignore []string, opts ...RunFile opts = append([]RunFileTestOption{WithSyncWanted(*withSync)}, opts...) - files, err := os.ReadDir(baseDir) + files, err := readFiles(t, baseDir) if err != nil { t.Fatal(err) } files = filterFileTests(t, files, ignore) - + var path string + var name string for _, file := range files { - file := file - t.Run(file.Name(), func(t *testing.T) { - if file.Name() == "composite0b.gno" { - t.Skip("challenge failing") - } - if file.Name() == "composite1b.gno" { - t.Skip("challenge failing") - } - if file.Name() == "not_a_type.gno" { - t.Skip("challenge failing") - } - if file.Name() == "unused0.gno" { - t.Skip("challenge failing") - } - - runFileTest(t, filepath.Join(baseDir, file.Name()), opts...) + path = file.path + name = strings.TrimPrefix(file.path, baseDir+string(os.PathSeparator)) + t.Run(name, func(t *testing.T) { + runFileTest(t, path, opts...) }) } } +// it reads all files recursively in the directory +func readFiles(t *testing.T, dir string) ([]testFile, error) { + t.Helper() + var files []testFile + + err := filepath.WalkDir(dir, func(path string, de fs.DirEntry, err error) error { + if err != nil { + return err + } + if de.IsDir() && de.Name() == "extern" { + return filepath.SkipDir + } + f := testFile{path: path, DirEntry: de} + + files = append(files, f) + return nil + }) + return files, err +} + +func filterFileTests(t *testing.T, files []testFile, ignore []string) []testFile { + t.Helper() + filtered := make([]testFile, 0, 1000) + var name string + + for _, f := range files { + // skip none .gno files + name = f.DirEntry.Name() + if filepath.Ext(name) != ".gno" { + continue + } + // skip ignored files + if isIgnored(t, name, ignore) { + continue + } + // skip _long file if we only want to test regular file. + if testing.Short() && strings.Contains(name, "_long") { + t.Logf("skipping test %s in short mode.", name) + continue + } + filtered = append(filtered, f) + } + return filtered +} + +func isIgnored(t *testing.T, name string, ignore []string) bool { + t.Helper() + isIgnore := false + for _, is := range ignore { + match, err := path.Match(is, name) + if err != nil { + t.Fatalf("error parsing glob pattern %q: %v", is, err) + } + if match { + isIgnore = true + break + } + } + return isIgnore +} + func runFileTest(t *testing.T, path string, opts ...RunFileTestOption) { t.Helper() diff --git a/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type2_filetest.gno new file mode 100644 index 00000000000..38ec5ab7851 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type2_filetest.gno @@ -0,0 +1,16 @@ +package main + +type ( + nat []int + nat64 []int64 +) + +func main() { + var nlist = nat{0} + var n64list = nat64{1} + a := append(n64list, nlist...) + println(a) +} + +// Error: +// main/files/assign_unnamed_type/append/named_unnamed_type2_filetest.gno:11: cannot use int as int64 diff --git a/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno new file mode 100644 index 00000000000..912aedb468d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno @@ -0,0 +1,15 @@ +package main + +type nat []int + +func main() { + var nlist = nat{0} + var ulist = []int{1} + + a := append(nlist, nlist[0], ulist[0]) + println(a) + +} + +// Output: +// (slice[(0 int),(0 int),(1 int)] main.nat) diff --git a/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno new file mode 100644 index 00000000000..7c37919f514 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno @@ -0,0 +1,35 @@ +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/gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno b/gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno new file mode 100644 index 00000000000..0351f4f62db --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/method/declaredType0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType0_filetest.gno new file mode 100644 index 00000000000..4c6ff69524d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType0_filetest.gno @@ -0,0 +1,19 @@ +package main + +type ( + word uint + 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/gnovm/tests/files/assign_unnamed_type/method/declaredType0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType0b_filetest.gno new file mode 100644 index 00000000000..65057890011 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType0b_filetest.gno @@ -0,0 +1,22 @@ +package main + +type ( + word int + 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/gnovm/tests/files/assign_unnamed_type/method/declaredType1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType1_filetest.gno new file mode 100644 index 00000000000..e56b4e08096 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType1_filetest.gno @@ -0,0 +1,27 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType1b_filetest.gno new file mode 100644 index 00000000000..364070cdc0d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType1b_filetest.gno @@ -0,0 +1,27 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno new file mode 100644 index 00000000000..71d3601ebef --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno @@ -0,0 +1,27 @@ +package main + +type ( + word uint + 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/gnovm/tests/files/assign_unnamed_type/method/declaredType2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType2b_filetest.gno new file mode 100644 index 00000000000..111d3311f98 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType2b_filetest.gno @@ -0,0 +1,26 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3_filetest.gno new file mode 100644 index 00000000000..d7ab3701b1a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType3_filetest.gno @@ -0,0 +1,22 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3b_filetest.gno new file mode 100644 index 00000000000..5dedb25b796 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType3b_filetest.gno @@ -0,0 +1,22 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3c_filetest.gno new file mode 100644 index 00000000000..f4eae2d2107 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType3c_filetest.gno @@ -0,0 +1,26 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType3d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3d_filetest.gno new file mode 100644 index 00000000000..c77e6c99669 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType3d_filetest.gno @@ -0,0 +1,22 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType4_filetest.gno new file mode 100644 index 00000000000..2bba41fa617 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType4_filetest.gno @@ -0,0 +1,23 @@ +package main + +type ( + word uint + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType5_filetest.gno new file mode 100644 index 00000000000..dd76ef1b1b8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType5_filetest.gno @@ -0,0 +1,24 @@ +package main + +type ( + BasicFunc func(int, int) int + 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 diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno new file mode 100644 index 00000000000..5d994352f35 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno @@ -0,0 +1,20 @@ +package main + +type ( + c uint + word c + nat []word +) + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + abs = []c{0} + println(abs.add()) +} + +// Error: +// main/files/assign_unnamed_type/method/declaredType6_filetest.gno:15: cannot use main.c as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno new file mode 100644 index 00000000000..88b3203a805 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno @@ -0,0 +1,20 @@ +package main + +type ( + c uint + word c + nat []word +) + +func (n nat) add() bool { + return true +} + +func main() { + var abs nat + abs = []uint{0} + println(abs.add()) +} + +// Error: +// main/files/assign_unnamed_type/method/declaredType6b_filetest.gno:15: cannot use uint as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/more/assgin_interface2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface2_filetest.gno new file mode 100644 index 00000000000..129eb8d749a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface2_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/gnovm/tests/files/assign_unnamed_type/more/assgin_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface_filetest.gno new file mode 100644 index 00000000000..92e3a1e3075 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface_filetest.gno @@ -0,0 +1,39 @@ +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/gnovm/tests/files/assign_unnamed_type/more/assgin_two_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assgin_two_filetest.gno new file mode 100644 index 00000000000..0ee4acd58fc --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/assgin_two_filetest.gno @@ -0,0 +1,18 @@ +package main + +type ( + nat []int + nat2 []int +) + +func main() { + a := nat{0} + b := nat2{1} + a = b + + println(a) + println(b) +} + +// Error: +// main/files/assign_unnamed_type/more/assgin_two_filetest.gno:11: cannot use main.nat2 as main.nat without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/more/assignment_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assignment_filetest.gno new file mode 100644 index 00000000000..2972c1895fd --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/assignment_filetest.gno @@ -0,0 +1,26 @@ +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/gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno new file mode 100644 index 00000000000..aeaabfedd1d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno @@ -0,0 +1,24 @@ +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) +} + +// Output: +// (slice[(0 int)] main.nat) +// slice[(1 int)] +// (slice[(1 int)] main.nat) +// slice[(1 int)] diff --git a/gnovm/tests/files/assign_unnamed_type/more/convert_types_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/convert_types_filetest.gno new file mode 100644 index 00000000000..0ff0a61c295 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/convert_types_filetest.gno @@ -0,0 +1,21 @@ +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/gnovm/tests/files/assign_unnamed_type/more/cross_realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/cross_realm_compositelit_filetest.gno new file mode 100644 index 00000000000..1bc5add0440 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/cross_realm_compositelit_filetest.gno @@ -0,0 +1,13 @@ +// PKGPATH: gno.land/r/declaredtype_test +package declaredtype_test + +import ( + "gno.land/r/demo/tests" +) + +func main() { + println(tests.GetZeroType()) +} + +// Output: +// (slice[(0 gno.land/r/demo/tests.Word)] gno.land/r/demo/tests.nat) diff --git a/gnovm/tests/files/assign_unnamed_type/more/declaredtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/declaredtype2_filetest.gno new file mode 100644 index 00000000000..c697abc0584 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/declaredtype2_filetest.gno @@ -0,0 +1,33 @@ +package main + +type ( + nat []Word + 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/gnovm/tests/files/assign_unnamed_type/more/default_value_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/default_value_filetest.gno new file mode 100644 index 00000000000..bb590f60dae --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/default_value_filetest.gno @@ -0,0 +1,31 @@ +package main + +type ( + nat []int + nmap map[int]int + 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/gnovm/tests/files/assign_unnamed_type/more/errors2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/errors2_filetest.gno new file mode 100644 index 00000000000..2588b904a77 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/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/gnovm/tests/files/assign_unnamed_type/more/method38d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38d_filetest.gno new file mode 100644 index 00000000000..09588bd5c10 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/method38d_filetest.gno @@ -0,0 +1,21 @@ +package main + +type ( + nat []Word + 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/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest.gno new file mode 100644 index 00000000000..f140d4b7291 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest.gno @@ -0,0 +1,22 @@ +package main + +type ( + nat []Word + 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/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest0.gno b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest0.gno new file mode 100644 index 00000000000..f140d4b7291 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest0.gno @@ -0,0 +1,22 @@ +package main + +type ( + nat []Word + 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/gnovm/tests/files/assign_unnamed_type/more/method38g_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38g_filetest.gno new file mode 100644 index 00000000000..2c41bbb0a97 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/method38g_filetest.gno @@ -0,0 +1,34 @@ +package main + +type ( + nat []Word + 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/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno new file mode 100644 index 00000000000..6549d1824ed --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno @@ -0,0 +1,228 @@ +// PKGPATH: gno.land/r/test +package test + +import ( + "fmt" +) + +type ( + word uint + 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", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/test", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "main.gno", +// "Line": "20", +// "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/gnovm/tests/files/assign_unnamed_type/more/recover6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/recover6_filetest.gno new file mode 100644 index 00000000000..0b304369764 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/recover6_filetest.gno @@ -0,0 +1,30 @@ +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/gnovm/tests/files/assign_unnamed_type/more/return2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return2_filetest.gno new file mode 100644 index 00000000000..2bdfdb474fe --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/return2_filetest.gno @@ -0,0 +1,16 @@ +package main + +func x() (int, int) { + return 1, 2 +} + +func main() { + var a, b int + a, b = x() + println(a) + println(b) +} + +// Output: +// 1 +// 2 diff --git a/gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno new file mode 100644 index 00000000000..9395426cfc8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno @@ -0,0 +1,15 @@ +package main + +func x1() interface{} { + a := "1" + return a +} + +func main() { + var a uint + a = x1() // should fail + println("1") +} + +// Error: +// main/files/assign_unnamed_type/more/return_interface1_filetest.gno:10: cannot use interface{} as uint diff --git a/gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno new file mode 100644 index 00000000000..8b5fdd7c728 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno @@ -0,0 +1,19 @@ +package main + +type nat []int + +func x() interface{} { + a := nat{0} + return a +} + +func main() { + var a nat + + a = x() + + println(a) +} + +// Error: +// main/files/assign_unnamed_type/more/return_interface_filetest.gno:13: cannot use interface{} as []int diff --git a/gnovm/tests/files/assign_unnamed_type/more/return_select_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_select_filetest.gno new file mode 100644 index 00000000000..cf5be970423 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more/return_select_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/type40.gno b/gnovm/tests/files/assign_unnamed_type/type40.gno new file mode 100644 index 00000000000..324b33290f5 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/type40.gno @@ -0,0 +1,20 @@ +package main + +type Set map[string]struct{} + +func NewSet(items ...string) Set { + return map[string]struct{}{} +} + +func (s Set) Has(key string) bool { + _, ok := s[key] + return ok +} + +func main() { + s := NewSet() + println(s.Has("a")) +} + +// Output: +// false diff --git a/gnovm/tests/files/assign_unnamed_type/unnamedtype0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype0_filetest.gno new file mode 100644 index 00000000000..5876111b324 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype0_filetest.gno @@ -0,0 +1,17 @@ +package main + +type ( + nat []word + word int +) + +func main() { + var a nat + b := []word{0} + a = b + + println(a) +} + +// Output: +// (slice[(0 main.word)] main.nat) diff --git a/gnovm/tests/files/assign_unnamed_type/unnamedtype0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype0b_filetest.gno new file mode 100644 index 00000000000..cc1d54cfa2a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype0b_filetest.gno @@ -0,0 +1,17 @@ +package main + +type ( + nat []int + word int +) + +func main() { + var a nat + b := []word{0} + a = b + + println(a) +} + +// Error: +// main/files/assign_unnamed_type/unnamedtype0b_filetest.gno:11: cannot use main.word as int without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/unnamedtype1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1_filetest.gno new file mode 100644 index 00000000000..d8cb730f90f --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype1_filetest.gno @@ -0,0 +1,24 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype1a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1a_filetest.gno new file mode 100644 index 00000000000..63cc382039e --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype1a_filetest.gno @@ -0,0 +1,23 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1b_filetest.gno new file mode 100644 index 00000000000..c440cf974cd --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype1b_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype1c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1c_filetest.gno new file mode 100644 index 00000000000..aa5533bd0e8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype1c_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2_filetest.gno new file mode 100644 index 00000000000..132242f83ea --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype2_filetest.gno @@ -0,0 +1,23 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype2a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2a_filetest.gno new file mode 100644 index 00000000000..5f25b9333ea --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype2a_filetest.gno @@ -0,0 +1,23 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2b_filetest.gno new file mode 100644 index 00000000000..0e7c4992fa5 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype2b_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype2c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2c_filetest.gno new file mode 100644 index 00000000000..9fc0e0f06a4 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype2c_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3_filetest.gno new file mode 100644 index 00000000000..ccc5cc2bb75 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype3_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype3a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3a_filetest.gno new file mode 100644 index 00000000000..06c2e3f5a4d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype3a_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3b_filetest.gno new file mode 100644 index 00000000000..e9c9b80418e --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype3b_filetest.gno @@ -0,0 +1,29 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3c_filetest.gno new file mode 100644 index 00000000000..5d506ab9566 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype3c_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4_filetest.gno new file mode 100644 index 00000000000..f384f71975f --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype4_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype4a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4a_filetest.gno new file mode 100644 index 00000000000..6c3b0856df9 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype4a_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype4b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4b_filetest.gno new file mode 100644 index 00000000000..15975fc588e --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype4b_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype4c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4c_filetest.gno new file mode 100644 index 00000000000..d6efcaded75 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype4c_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno new file mode 100644 index 00000000000..583e2f12bd8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno @@ -0,0 +1,41 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno new file mode 100644 index 00000000000..e14e64e4dfd --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno @@ -0,0 +1,32 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype5b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5b_filetest.gno new file mode 100644 index 00000000000..80f8c224e6c --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5b_filetest.gno @@ -0,0 +1,30 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype5c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5c_filetest.gno new file mode 100644 index 00000000000..aa5533bd0e8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5c_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6_filetest.gno new file mode 100644 index 00000000000..41c72c390a1 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype6_filetest.gno @@ -0,0 +1,24 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype6a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6a_filetest.gno new file mode 100644 index 00000000000..37e3951df55 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype6a_filetest.gno @@ -0,0 +1,24 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6b_filetest.gno new file mode 100644 index 00000000000..e57821f8b7d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype6b_filetest.gno @@ -0,0 +1,27 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype6c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6c_filetest.gno new file mode 100644 index 00000000000..1c17c204fe8 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype6c_filetest.gno @@ -0,0 +1,25 @@ +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/gnovm/tests/files/assign_unnamed_type/unnamedtype7_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype7_filetest.gno new file mode 100644 index 00000000000..939428bd192 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/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/gnovm/tests/files/print1.gno b/gnovm/tests/files/print1.gno index 606759a5c05..15c9e7bb278 100644 --- a/gnovm/tests/files/print1.gno +++ b/gnovm/tests/files/print1.gno @@ -6,4 +6,4 @@ func main() { } // Output: -// nil []string +// (nil []string) diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 9542b5e8d1a..d68c1f652f7 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,157 @@ 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", +// "NativeName": "", +// "NativePkg": "", +// "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": [ // { @@ -455,7 +606,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", @@ -464,6 +625,164 @@ func main() { // "Escaped": true, // "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" // }, +// "FileName": "realm_compositelit.gno", +// "IsMethod": false, +// "Name": "GetZeroType", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_compositelit.gno", +// "Line": "19", +// "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", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "9", +// "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", +// "NativeName": "", +// "NativePkg": "", +// "PkgPath": "gno.land/r/demo/tests", +// "Source": { +// "@type": "/gno.RefNode", +// "BlockNode": null, +// "Location": { +// "File": "realm_method38d.gno", +// "Line": "15", +// "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", @@ -508,7 +827,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -564,7 +883,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -620,7 +939,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -666,7 +985,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -712,7 +1031,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -758,7 +1077,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -804,7 +1123,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -863,7 +1182,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -912,7 +1231,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -948,7 +1267,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -984,7 +1303,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1030,7 +1349,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1086,7 +1405,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1143,7 +1462,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1192,8 +1511,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "5e5535af7afef6f523a897c051944639ef56c057", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9" +// "Hash": "5f12a61dd16d828be8584debc0e395e8d2136acb", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13" // }, // "Length": "3", // "Maxcap": "3", @@ -1202,6 +1521,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" // } @@ -1245,7 +1595,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"]