From 2fd4c9b63adf16ff4195519c27a16dfdc27dfd2f Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Sun, 15 Oct 2023 15:37:08 -0700 Subject: [PATCH 1/9] feat:named and unnamed type assignment 2 of 3 --- .../r/demo/tests/realm_compositelit.gno | 22 + .../gno.land/r/demo/tests/realm_method38d.gno | 19 + gnovm/pkg/gnolang/preprocess.go | 60 ++- gnovm/pkg/gnolang/types.go | 77 +++ gnovm/pkg/gnolang/values_string.go | 22 +- gnovm/tests/file_test.go | 99 ++-- .../append_named_unnamed_type2_filetest.gno | 16 + .../append_named_unnamed_type3_filetest.gno | 14 + .../append_named_unnamed_type_filetest.gno | 38 ++ .../assign_unnamedtype0_filetest.gno | 15 + .../assign_unnamedtype0b_filetest.gno | 15 + .../assign_unnamedtype1_filetest.gno | 26 + .../assign_unnamedtype1a_filetest.gno | 26 + .../assign_unnamedtype1b_filetest.gno | 30 ++ .../assign_unnamedtype1c_filetest.gno | 28 ++ .../assign_unnamedtype2_filetest.gno | 25 + .../assign_unnamedtype2a_filetest.gno | 26 + .../assign_unnamedtype2b_filetest.gno | 30 ++ .../assign_unnamedtype2c_filetest.gno | 28 ++ .../assign_unnamedtype3_filetest.gno | 27 + .../assign_unnamedtype3a_filetest.gno | 28 ++ .../assign_unnamedtype3b_filetest.gno | 32 ++ .../assign_unnamedtype3c_filetest.gno | 30 ++ .../assign_unnamedtype4_filetest.gno | 29 ++ .../assign_unnamedtype4a_filetest.gno | 30 ++ .../assign_unnamedtype4b_filetest.gno | 30 ++ .../assign_unnamedtype4c_filetest.gno | 28 ++ .../assign_unnamedtype5_filetest.gno | 44 ++ .../assign_unnamedtype5a_filetest.gno | 37 ++ .../assign_unnamedtype5b_filetest.gno | 37 ++ .../assign_unnamedtype5c_filetest.gno | 28 ++ .../assign_unnamedtype6_filetest.gno | 26 + .../assign_unnamedtype6a_filetest.gno | 27 + .../assign_unnamedtype6b_filetest.gno | 30 ++ .../assign_unnamedtype6c_filetest.gno | 28 ++ .../assign_unnamedtype7_filetest.gno | 15 + .../copy/copy_name_unnamed_filetest.gno | 27 + .../declaredType0_filetest.gno | 17 + .../declaredType0b_filetest.gno | 20 + .../declaredType1_filetest.gno | 25 + .../declaredType1b_filetest.gno | 25 + .../declaredType2_filetest.gno | 22 + .../declaredType2b_filetest.gno | 24 + .../declaredType3_filetest.gno | 20 + .../declaredType3b_filetest.gno | 20 + .../declaredType3c_filetest.gno | 24 + .../declaredType3d_filetest.gno | 20 + .../declaredType4_filetest.gno | 22 + .../declaredType5_filetest.gno | 22 + .../declaredType6_filetest.gno | 20 + .../declaredType6b_filetest.gno | 20 + .../assgin_interface2_filetest.gno | 14 + .../assgin_interface_filetest.gno | 40 ++ .../more_filetest/assgin_two_filetest.gno | 16 + .../more_filetest/assignment_filetest.gno | 27 + .../convert_types1b_filetest.gno | 19 + .../more_filetest/convert_types_filetest.gno | 23 + .../cross_realm_compositelit_filetest.gno | 14 + .../more_filetest/declaredtype2_filetest.gno | 32 ++ .../more_filetest/default_value_filetest.gno | 30 ++ .../more_filetest/errors2_filetest.gno | 17 + .../more_filetest/method38d_filetest.gno | 20 + .../more_filetest/method38e_filetest.gno | 21 + .../more_filetest/method38e_filetest0.gno | 21 + .../more_filetest/method38g_filetest.gno | 30 ++ .../realm_compositelit_filetest.gno | 225 +++++++++ .../more_filetest/recover6_filetest.gno | 32 ++ .../more_filetest/return2_filetest.gno | 18 + .../return_interface1_filetest.gno | 16 + .../return_interface_filetest.gno | 20 + .../more_filetest/return_select_filetest.gno | 28 ++ gnovm/tests/files/zrealm_tests0.gno | 468 ++++++++++++++++-- 72 files changed, 2513 insertions(+), 68 deletions(-) create mode 100644 examples/gno.land/r/demo/tests/realm_compositelit.gno create mode 100644 examples/gno.land/r/demo/tests/realm_method38d.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype7_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/errors2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno 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 e02a158fcf1..2944e64ba09 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)) @@ -2146,12 +2151,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 +2313,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,13 +2340,52 @@ 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) func convertIfConst(store Store, last BlockNode, x Expr) { if cx, ok := x.(*ConstExpr); ok { diff --git a/gnovm/pkg/gnolang/types.go b/gnovm/pkg/gnolang/types.go index c3e439e9427..02e1ce3fadf 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,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 @@ -1333,6 +1374,10 @@ func (mt *MapType) GetPkgPath() string { return "" } +func (mt *MapType) IsNamed() bool { + return false +} + // ---------------------------------------- // Type (typeval) type @@ -1361,6 +1406,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 +1494,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 +1764,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 +1900,10 @@ func (bt blockType) GetPkgPath() string { panic("blockType has no package path") } +func (bt blockType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // tupleType @@ -1889,6 +1954,10 @@ func (tt *tupleType) GetPkgPath() string { panic("typleType has no package path") } +func (tt *tupleType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // RefType @@ -1916,6 +1985,10 @@ func (rt RefType) GetPkgPath() string { panic("should not happen") } +func (rt RefType) IsNamed() bool { + panic("unexpected") +} + // ---------------------------------------- // MaybeNativeType @@ -1946,6 +2019,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/values_string.go b/gnovm/pkg/gnolang/values_string.go index f9a0128d7f9..1eda846f75d 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -227,11 +227,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/file_test.go b/gnovm/tests/file_test.go index f070546ab74..4e926191bb8 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -3,7 +3,6 @@ package tests import ( "flag" "io/fs" - "os" "path" "path/filepath" "strings" @@ -37,31 +36,9 @@ func TestChallenges(t *testing.T) { 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,21 +47,81 @@ 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) { - runFileTest(t, filepath.Join(baseDir, file.Name()), opts...) + path = file.path + name = file.DirEntry.Name() + 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 + } + 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/append_named_unnamed_type2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno new file mode 100644 index 00000000000..3831d81829d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno @@ -0,0 +1,16 @@ +package main + +type nat []int +type 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/append_named_unnamed_type2_filetest.gno:10: cannot use int as int64 diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno new file mode 100644 index 00000000000..ba90fea7a39 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno @@ -0,0 +1,14 @@ +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/append_named_unnamed_type_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno new file mode 100644 index 00000000000..f9ebb53eeff --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/append/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno new file mode 100644 index 00000000000..c722fa50c9c --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno new file mode 100644 index 00000000000..2a7285a0bb9 --- /dev/null +++ b/gnovm/tests/files/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/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno:9: cannot use main.word as int without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno new file mode 100644 index 00000000000..35a2fef7c51 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno new file mode 100644 index 00000000000..cb13467ecdc --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno new file mode 100644 index 00000000000..752a10f7ecf --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno new file mode 100644 index 00000000000..621d478a811 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno new file mode 100644 index 00000000000..9148def9d91 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno new file mode 100644 index 00000000000..754507055b1 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno new file mode 100644 index 00000000000..9ac3ed6f97a --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno new file mode 100644 index 00000000000..ee2057251db --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno new file mode 100644 index 00000000000..aa466be2216 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno new file mode 100644 index 00000000000..385bbaaf43c --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno new file mode 100644 index 00000000000..4e34cf38ad7 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno new file mode 100644 index 00000000000..d0e1a1bbffe --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno new file mode 100644 index 00000000000..5fe5b4f11a9 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno new file mode 100644 index 00000000000..dd56f229be2 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno new file mode 100644 index 00000000000..8a6ef440ee8 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno new file mode 100644 index 00000000000..30b9db76eee --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno new file mode 100644 index 00000000000..da1da6ce906 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno new file mode 100644 index 00000000000..2cdbabab1d5 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno new file mode 100644 index 00000000000..31055fed80d --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno new file mode 100644 index 00000000000..621d478a811 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno new file mode 100644 index 00000000000..cc9aad71ec2 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno new file mode 100644 index 00000000000..6fc993708c8 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno new file mode 100644 index 00000000000..2fc593f7bc1 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno new file mode 100644 index 00000000000..1e80a93ab1b --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype7_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype7_filetest.gno new file mode 100644 index 00000000000..939428bd192 --- /dev/null +++ b/gnovm/tests/files/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/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno b/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno new file mode 100644 index 00000000000..6ada04f3a9a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno new file mode 100644 index 00000000000..4aa8ff10d97 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno new file mode 100644 index 00000000000..b053442c2d4 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno new file mode 100644 index 00000000000..2a0d1f5c500 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno new file mode 100644 index 00000000000..e4f53cb172a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno new file mode 100644 index 00000000000..b4f5b0d6f69 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno @@ -0,0 +1,22 @@ +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()) + } \ No newline at end of file diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno new file mode 100644 index 00000000000..9d37b0dbaee --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno new file mode 100644 index 00000000000..c2a98cb3a3a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno new file mode 100644 index 00000000000..960197f5c04 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno new file mode 100644 index 00000000000..15a2fc048ac --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno new file mode 100644 index 00000000000..5b3148a4c94 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno new file mode 100644 index 00000000000..69bd9206aed --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno new file mode 100644 index 00000000000..ee22bb38c30 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno new file mode 100644 index 00000000000..c71bbceac3d --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno:14: cannot use main.c as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno new file mode 100644 index 00000000000..e70c82712a6 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/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/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno:14: cannot use uint as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface2_filetest.gno new file mode 100644 index 00000000000..129eb8d749a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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_filetest/assgin_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno new file mode 100644 index 00000000000..0712cf1e1c6 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_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/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno new file mode 100644 index 00000000000..2ce406d1cc1 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno:9: cannot use main.nat2 as main.nat without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno new file mode 100644 index 00000000000..ebcbcff37a1 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno new file mode 100644 index 00000000000..593c02204a5 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno @@ -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/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno new file mode 100644 index 00000000000..4fd038a60cc --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno new file mode 100644 index 00000000000..d6158df91a2 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno @@ -0,0 +1,14 @@ +// 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_filetest/declaredtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno new file mode 100644 index 00000000000..6c2e0fa38d6 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno new file mode 100644 index 00000000000..5612f9a84d4 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/errors2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/errors2_filetest.gno new file mode 100644 index 00000000000..2588b904a77 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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_filetest/method38d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno new file mode 100644 index 00000000000..48599c922ba --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno new file mode 100644 index 00000000000..ba99f45adb3 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno new file mode 100644 index 00000000000..ba99f45adb3 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno new file mode 100644 index 00000000000..f2f4509e82a --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno new file mode 100644 index 00000000000..1efa2348052 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno new file mode 100644 index 00000000000..11186cdb200 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_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/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno new file mode 100644 index 00000000000..007b613247c --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno @@ -0,0 +1,18 @@ +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_filetest/return_interface1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno new file mode 100644 index 00000000000..19d6e38d8b2 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno:10: cannot use interface{} as uint diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno new file mode 100644 index 00000000000..478a4b3b7a9 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno:13: cannot use interface{} as []int diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno new file mode 100644 index 00000000000..3f19e25caf5 --- /dev/null +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/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/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index cfb1f08c6f4..614083b86be 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": "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", +// "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", +// "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", @@ -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, @@ -914,7 +1295,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -968,7 +1349,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1023,7 +1404,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1070,8 +1451,8 @@ func main() { // "@type": "/gno.SliceValue", // "Base": { // "@type": "/gno.RefValue", -// "Hash": "5e5535af7afef6f523a897c051944639ef56c057", -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:9" +// "Hash": "5f12a61dd16d828be8584debc0e395e8d2136acb", +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:13" // }, // "Length": "3", // "Maxcap": "3", @@ -1080,6 +1461,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" // } @@ -1113,7 +1525,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"] From 0b37e541115b417b38a4a3bf49deaaa361e0618e Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Mon, 6 Nov 2023 10:38:23 -0800 Subject: [PATCH 2/9] Update gnovm/pkg/gnolang/values_string.go Co-authored-by: deelawn --- gnovm/pkg/gnolang/values_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index 1eda846f75d..9c3b97d1f9f 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -247,7 +247,7 @@ func (tv *TypedValue) Sprint(m *Machine) string { return mv.String() default: panic(fmt.Sprintf( - "unexpected slice type %v", + "unexpected map type %v", reflect.TypeOf(tv.V))) } case *FuncType: From e81b68262a526ae22913b1f2290b9d7767d5acf5 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Thu, 9 Nov 2023 13:14:19 +0100 Subject: [PATCH 3/9] gofumpt tests/files/assign_unnamed_type --- .../append_named_unnamed_type2_filetest.gno | 16 ++++---- .../append_named_unnamed_type3_filetest.gno | 8 ++-- .../append_named_unnamed_type_filetest.gno | 20 ++++------ .../assign_unnamedtype0_filetest.gno | 6 ++- .../assign_unnamedtype0b_filetest.gno | 8 ++-- .../assign_unnamedtype1_filetest.gno | 2 - .../assign_unnamedtype1a_filetest.gno | 3 -- .../assign_unnamedtype1b_filetest.gno | 3 -- .../assign_unnamedtype1c_filetest.gno | 3 -- .../assign_unnamedtype2_filetest.gno | 2 - .../assign_unnamedtype2a_filetest.gno | 3 -- .../assign_unnamedtype2b_filetest.gno | 3 -- .../assign_unnamedtype2c_filetest.gno | 3 -- .../assign_unnamedtype3_filetest.gno | 2 - .../assign_unnamedtype3a_filetest.gno | 3 -- .../assign_unnamedtype3b_filetest.gno | 3 -- .../assign_unnamedtype3c_filetest.gno | 3 -- .../assign_unnamedtype4_filetest.gno | 2 - .../assign_unnamedtype4a_filetest.gno | 3 -- .../assign_unnamedtype4b_filetest.gno | 3 -- .../assign_unnamedtype4c_filetest.gno | 3 -- .../assign_unnamedtype5_filetest.gno | 5 +-- .../assign_unnamedtype5a_filetest.gno | 5 --- .../assign_unnamedtype5b_filetest.gno | 7 ---- .../assign_unnamedtype5c_filetest.gno | 3 -- .../assign_unnamedtype6_filetest.gno | 2 - .../assign_unnamedtype6a_filetest.gno | 3 -- .../assign_unnamedtype6b_filetest.gno | 3 -- .../assign_unnamedtype6c_filetest.gno | 3 -- .../copy/copy_name_unnamed_filetest.gno | 8 ++-- .../declaredType0_filetest.gno | 6 ++- .../declaredType0b_filetest.gno | 6 ++- .../declaredType1_filetest.gno | 40 ++++++++++--------- .../declaredType1b_filetest.gno | 38 +++++++++--------- .../declaredType2_filetest.gno | 30 +++++++------- .../declaredType2b_filetest.gno | 34 ++++++++-------- .../declaredType3_filetest.gno | 28 +++++++------ .../declaredType3b_filetest.gno | 28 +++++++------ .../declaredType3c_filetest.gno | 32 ++++++++------- .../declaredType3d_filetest.gno | 28 +++++++------ .../declaredType4_filetest.gno | 33 +++++++-------- .../declaredType5_filetest.gno | 34 ++++++++-------- .../declaredType6_filetest.gno | 10 +++-- .../declaredType6b_filetest.gno | 10 +++-- .../assgin_interface_filetest.gno | 1 - .../more_filetest/assgin_two_filetest.gno | 8 ++-- .../more_filetest/assignment_filetest.gno | 1 - .../convert_types1b_filetest.gno | 17 ++++---- .../more_filetest/convert_types_filetest.gno | 4 +- .../cross_realm_compositelit_filetest.gno | 1 - .../more_filetest/declaredtype2_filetest.gno | 7 ++-- .../more_filetest/default_value_filetest.gno | 11 ++--- .../more_filetest/method38d_filetest.gno | 7 ++-- .../more_filetest/method38e_filetest.gno | 7 ++-- .../more_filetest/method38e_filetest0.gno | 7 ++-- .../more_filetest/method38g_filetest.gno | 8 +++- .../realm_compositelit_filetest.gno | 9 +++-- .../more_filetest/recover6_filetest.gno | 2 - .../more_filetest/return2_filetest.gno | 2 - .../return_interface1_filetest.gno | 1 - .../return_interface_filetest.gno | 1 - .../more_filetest/return_select_filetest.gno | 3 -- 62 files changed, 272 insertions(+), 323 deletions(-) diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno index 3831d81829d..cd8764845b1 100644 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno @@ -1,16 +1,16 @@ package main -type nat []int -type nat64 []int64 +type ( + nat []int + nat64 []int64 +) func main() { - - var nlist = nat{0} - var n64list = nat64{1} + nlist := nat{0} + n64list := nat64{1} a := append(n64list, nlist...) - println(a) - + println(a) } // Error: -// main/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno:10: cannot use int as int64 +// main/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno:11: cannot use int as int64 diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno index ba90fea7a39..ff342ee7aa9 100644 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno @@ -1,13 +1,13 @@ package main type nat []int + func main() { - var nlist = nat{0} - var ulist = []int{1} + nlist := nat{0} + ulist := []int{1} a := append(nlist, nlist[0], ulist[0]) - println(a) - + println(a) } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno index f9ebb53eeff..e5df7ede65a 100644 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno @@ -1,20 +1,17 @@ package main - - type nat []int func main() { - - var nlist = nat{0} - var ulist = []int{1} + nlist := nat{0} + ulist := []int{1} var n int = 3 a := append(nlist, n) b := append(ulist, n) - println(a) - println(b) + println(a) + println(b) a = append(ulist, n) b = append(nlist, n) @@ -22,11 +19,10 @@ func main() { c := append(nlist, ulist...) d := append(ulist, nlist...) - println(a) - println(b) - println(c) - println(d) - + println(a) + println(b) + println(c) + println(d) } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno index c722fa50c9c..5876111b324 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno @@ -1,7 +1,9 @@ package main -type nat []word -type word int +type ( + nat []word + word int +) func main() { var a nat diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno index 2a7285a0bb9..f9feb479201 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno @@ -1,7 +1,9 @@ package main -type nat []int -type word int +type ( + nat []int + word int +) func main() { var a nat @@ -12,4 +14,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno:9: cannot use main.word as int without explicit conversion +// main/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno:11: cannot use main.word as int without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno index 35a2fef7c51..d8cb730f90f 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno @@ -3,7 +3,6 @@ package main type nat []int func main() { - var a nat a = []int{0} b := []int{1} @@ -16,7 +15,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno index cb13467ecdc..63cc382039e 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno @@ -4,11 +4,9 @@ type nat []int func (n nat) zero(num []int) { println(num) - } func (n nat) one(num nat) { - println(num) } @@ -18,7 +16,6 @@ func main() { a.zero(nat{0}) a.one([]int{1}) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno index 752a10f7ecf..c440cf974cd 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno @@ -3,12 +3,10 @@ package main type nat []int func (n nat) zero() nat { - return []int{0} } func (n nat) one() []int { - return nat{1} } @@ -20,7 +18,6 @@ func main() { println(a.zero().zero()) println(a.zero().one()) println(a.one()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno index 621d478a811..aa5533bd0e8 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno @@ -3,12 +3,10 @@ package main type nat []int func (n nat) zero() interface{} { - return []int{0} } func (n nat) one() interface{} { - return nat{1} } @@ -19,7 +17,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno index 9148def9d91..132242f83ea 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno @@ -3,7 +3,6 @@ package main type nat [1]int func main() { - var a nat a = [1]int{0} b := [1]int{1} @@ -15,7 +14,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno index 754507055b1..5f25b9333ea 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno @@ -4,11 +4,9 @@ type nat [1]int func (n nat) zero(num [1]int) { println(num) - } func (n nat) one(num nat) { - println(num) } @@ -18,7 +16,6 @@ func main() { a.zero(nat{0}) a.one([1]int{1}) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno index 9ac3ed6f97a..0e7c4992fa5 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno @@ -3,12 +3,10 @@ package main type nat [1]int func (n nat) zero() nat { - return [1]int{0} } func (n nat) one() [1]int { - return nat{1} } @@ -20,7 +18,6 @@ func main() { println(a.zero().zero()) println(a.zero().one()) println(a.one()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno index ee2057251db..9fc0e0f06a4 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno @@ -3,12 +3,10 @@ package main type nat [1]int func (n nat) zero() interface{} { - return [1]int{0} } func (n nat) one() interface{} { - return nat{1} } @@ -19,7 +17,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno index aa466be2216..ccc5cc2bb75 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno @@ -5,7 +5,6 @@ type nat struct { } func main() { - var a nat a = struct{ num int }{0} b := struct{ num int }{1} @@ -17,7 +16,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno index 385bbaaf43c..06c2e3f5a4d 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno @@ -6,11 +6,9 @@ type nat struct { func (n nat) zero(num struct{ num int }) { println(num) - } func (n nat) one(num nat) { - println(num) } @@ -20,7 +18,6 @@ func main() { a.zero(nat{0}) a.one(struct{ num int }{1}) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno index 4e34cf38ad7..e9c9b80418e 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno @@ -5,12 +5,10 @@ type nat struct { } func (n nat) zero() nat { - return struct{ num int }{0} } func (n nat) one() struct{ num int } { - return nat{1} } @@ -22,7 +20,6 @@ func main() { println(a.zero().zero()) println(a.zero().one()) println(a.one()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno index d0e1a1bbffe..5d506ab9566 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno @@ -5,12 +5,10 @@ type nat struct { } func (n nat) zero() interface{} { - return struct{ num int }{0} } func (n nat) one() interface{} { - return nat{1} } @@ -21,7 +19,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno index 5fe5b4f11a9..f384f71975f 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno @@ -3,7 +3,6 @@ package main type nat map[string]int func main() { - var a nat a = map[string]int{ @@ -19,7 +18,6 @@ func main() { b = a println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno index dd56f229be2..6c3b0856df9 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno @@ -4,11 +4,9 @@ type nat map[string]int func (n nat) zero(num map[string]int) { println(num) - } func (n nat) one(num nat) { - println(num) } @@ -22,7 +20,6 @@ func main() { a.one(map[string]int{ "zero": 1, }) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno index 8a6ef440ee8..15975fc588e 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno @@ -3,12 +3,10 @@ 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} } @@ -20,7 +18,6 @@ func main() { println(a.zero().zero()) println(a.zero().one()) println(a.one()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno index 30b9db76eee..d6efcaded75 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno @@ -3,12 +3,10 @@ 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} } @@ -19,7 +17,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno index da1da6ce906..583e2f12bd8 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno @@ -3,12 +3,11 @@ package main type op func(int) int func inc(n int) int { - n = n + 1 return n } -func dec(n int) int { +func dec(n int) int { n = n - 1 return n } @@ -18,7 +17,6 @@ func main() { a = inc b := func(n int) int { - return n } c := dec @@ -32,7 +30,6 @@ func main() { println(a(0), a) println(b(0), b) println(c(0), c) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno index 2cdbabab1d5..e14e64e4dfd 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno @@ -5,11 +5,9 @@ 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)) } @@ -17,18 +15,15 @@ func exec2(opFn op) { 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: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno index 31055fed80d..80f8c224e6c 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno @@ -3,12 +3,9 @@ package main type op func(int) int func popFn1() op { - return func(n int) int { - n = n + 1 return n - } } @@ -16,20 +13,16 @@ 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: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno index 621d478a811..aa5533bd0e8 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno @@ -3,12 +3,10 @@ package main type nat []int func (n nat) zero() interface{} { - return []int{0} } func (n nat) one() interface{} { - return nat{1} } @@ -19,7 +17,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno index cc9aad71ec2..41c72c390a1 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno @@ -3,7 +3,6 @@ package main type nat []interface{} func main() { - var a nat a = []interface{}{0} b := []interface{}{1} @@ -16,7 +15,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno index 6fc993708c8..37e3951df55 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno @@ -4,7 +4,6 @@ type nat []interface{} func (n nat) zero(num []interface{}) { println(num) - } func (n nat) one(num nat) { @@ -12,13 +11,11 @@ func (n nat) one(num nat) { } func main() { - var a nat a = []interface{}{} println(a) a.zero(nat{0}) a.one([]interface{}{1}) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno index 2fc593f7bc1..e57821f8b7d 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno @@ -4,7 +4,6 @@ type nat []interface{} func (n nat) zero() nat { return []interface{}{0} - } func (n nat) one() []interface{} { @@ -12,7 +11,6 @@ func (n nat) one() []interface{} { } func main() { - var a nat a = []interface{}{} @@ -20,7 +18,6 @@ func main() { println(a.zero().zero()) println(a.zero().one()) println(a.one()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno index 1e80a93ab1b..1c17c204fe8 100644 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno @@ -3,12 +3,10 @@ package main type nat []interface{} func (n nat) zero() interface{} { - return []interface{}{0} } func (n nat) one() interface{} { - return nat{1} } @@ -19,7 +17,6 @@ func main() { println(a.zero()) println(a.one()) println(a.one().(nat).zero()) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno b/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno index 6ada04f3a9a..525e28f2081 100644 --- a/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno @@ -3,9 +3,8 @@ package main type nat []int func main() { - - var nlist = nat{0} - var ulist = []int{1} + nlist := nat{0} + ulist := []int{1} copy(nlist, ulist) @@ -17,11 +16,10 @@ func main() { copy(ulist, nlist) println(nlist) println(ulist) - } // Output: // (slice[(1 int)] main.nat) // slice[(1 int)] // (slice[(0 int)] main.nat) -// slice[(0 int)] +// slice[(0 int)] diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno index 4aa8ff10d97..4c6ff69524d 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno @@ -1,7 +1,9 @@ package main -type word uint -type nat []word +type ( + word uint + nat []word +) func (n nat) add() bool { return true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno index b053442c2d4..65057890011 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno @@ -1,7 +1,9 @@ package main -type word int -type nat []word +type ( + word int + nat []word +) func (n nat) add() bool { return true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno index 2a0d1f5c500..e56b4e08096 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno @@ -1,25 +1,27 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - // structLit - type Int struct { - neg bool - abs nat - } +// structLit +type Int struct { + neg bool + abs nat +} - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - func main() { - z := &Int{ - neg: true, - abs: []word{0}, - } - println(z.abs.add()) - } +func main() { + z := &Int{ + neg: true, + abs: []word{0}, + } + println(z.abs.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno index e4f53cb172a..364070cdc0d 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno @@ -1,25 +1,27 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - type Int struct { - neg bool - abs nat - } +type Int struct { + neg bool + abs nat +} - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - func main() { - z := &Int{ - neg: true, - } +func main() { + z := &Int{ + neg: true, + } - z.abs = []word{0} - println(z.abs.add()) - } + z.abs = []word{0} + println(z.abs.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno index b4f5b0d6f69..3498cdf3f16 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno @@ -1,22 +1,24 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // map - func main() { - items := map[string]nat{} +// map +func main() { + items := map[string]nat{} - n := []word{0} + n := []word{0} - // this is assignment - items["test"] = n + // this is assignment + items["test"] = n - r := items["test"] + r := items["test"] - println(r.add()) - } \ No newline at end of file + println(r.add()) +} diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno index 9d37b0dbaee..111d3311f98 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno @@ -1,24 +1,26 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // mapLit - func main() { - n := []word{0} +// mapLit +func main() { + n := []word{0} - items := map[string]nat{ - "test": n, - } + items := map[string]nat{ + "test": n, + } - r := items["test"] + r := items["test"] - println(r.add()) - } + println(r.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno index c2a98cb3a3a..d7ab3701b1a 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno @@ -1,20 +1,22 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // sliceLit - func main() { - items := []nat{[]word{0}, []word{1}} +// sliceLit +func main() { + items := []nat{[]word{0}, []word{1}} - r := items[0] + r := items[0] - println(r.add()) - } + println(r.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno index 960197f5c04..5dedb25b796 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno @@ -1,20 +1,22 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // sliceLit2 - func main() { - items := []nat{1:[]word{0}, 2:[]word{1}} +// sliceLit2 +func main() { + items := []nat{1: []word{0}, 2: []word{1}} - r := items[1] + r := items[1] - println(r.add()) - } + println(r.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno index 15a2fc048ac..f4eae2d2107 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno @@ -1,24 +1,26 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // slice append - func main() { - var items []nat +// slice append +func main() { + var items []nat - n := []word{0} + n := []word{0} - items = append(items, n) + items = append(items, n) - r := items[0] + r := items[0] - println(r.add()) - } + println(r.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno index 5b3148a4c94..c77e6c99669 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno @@ -1,20 +1,22 @@ package main - type word uint - type nat []word +type ( + word uint + nat []word +) - func (n nat) add() bool { - return true - } +func (n nat) add() bool { + return true +} - // ArrayLit - func main() { - items := [3]nat{[]word{0}, []word{1}} +// ArrayLit +func main() { + items := [3]nat{[]word{0}, []word{1}} - r := items[0] + r := items[0] - println(r.add()) - } + println(r.add()) +} - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno index 69bd9206aed..2bba41fa617 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno @@ -1,22 +1,23 @@ package main +type ( + word uint + nat []word +) - type word uint - type nat []word +func (n nat) add(x, y nat) bool { + return true +} - 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} - // parameter - func main() { - var abs nat - abs = []word{0} - x := []word{1} - y := []word{2} + println(abs.add(x, y)) +} - println(abs.add(x, y)) - } - - // Output: - // true \ No newline at end of file +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno index ee22bb38c30..dd76ef1b1b8 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno @@ -1,22 +1,24 @@ package main - type BasicFunc func(int, int) int - type MyFunc BasicFunc +type ( + BasicFunc func(int, int) int + MyFunc BasicFunc +) - func (f MyFunc) Apply(a, b int) int { - return f(a, b) - } +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 +func main() { + basicAdd := func(a, b int) int { + return a + b + } + var myAdd MyFunc + myAdd = basicAdd - result := myAdd.Apply(2, 3) - println(result) - } + result := myAdd.Apply(2, 3) + println(result) +} - // Output: - // 5 \ No newline at end of file +// Output: +// 5 diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno index c71bbceac3d..a6953db5cef 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno @@ -1,8 +1,10 @@ package main -type c uint -type word c -type nat []word +type ( + c uint + word c + nat []word +) func (n nat) add() bool { return true @@ -17,4 +19,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno:14: cannot use main.c as main.word without explicit conversion +// main/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno:16: cannot use main.c as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno index e70c82712a6..382859b32d2 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno @@ -1,8 +1,10 @@ package main -type c uint -type word c -type nat []word +type ( + c uint + word c + nat []word +) func (n nat) add() bool { return true @@ -17,4 +19,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno:14: cannot use uint as main.word without explicit conversion +// main/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno:16: cannot use uint as main.word without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno index 0712cf1e1c6..92e3a1e3075 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno @@ -30,7 +30,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno index 2ce406d1cc1..e9abfc4dd11 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno @@ -1,7 +1,9 @@ package main -type nat []int -type nat2 []int +type ( + nat []int + nat2 []int +) func main() { a := nat{0} @@ -13,4 +15,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno:9: cannot use main.nat2 as main.nat without explicit conversion +// main/files/assign_unnamed_type/more_filetest/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_filetest/assignment_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno index ebcbcff37a1..2972c1895fd 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno @@ -17,7 +17,6 @@ func main() { println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno index 593c02204a5..983a4ab073d 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno @@ -3,17 +3,16 @@ package main type nat []int func main() { - var a nat - var b []int + var a nat + var b []int - a = (nat)([]int{0}) - b = ([]int)(nat{1}) - println(a) + a = (nat)([]int{0}) + b = ([]int)(nat{1}) + println(a) println(b) - a = (nat)(b) - b = ([]int)(a) - println(a) + a = (nat)(b) + b = ([]int)(a) + println(a) println(b) - } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno index 4fd038a60cc..0ff0a61c295 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno @@ -3,7 +3,6 @@ package main type nat []int func main() { - var b []int b = nat{1} println(b) @@ -14,10 +13,9 @@ func main() { b = a println(b) - } -//Output: +// Output: // slice[(1 int)] // (slice[(0 int)] main.nat) // slice[(0 int)] diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno index d6158df91a2..1bc5add0440 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno @@ -6,7 +6,6 @@ import ( ) func main() { - println(tests.GetZeroType()) } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno index 6c2e0fa38d6..c697abc0584 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno @@ -1,7 +1,9 @@ package main -type nat []Word -type Word uint +type ( + nat []Word + Word uint +) func main() { var abs []Word @@ -19,7 +21,6 @@ func main() { println(c) println(d) println(e) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno index 5612f9a84d4..bb590f60dae 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno @@ -1,7 +1,10 @@ package main -type nat []int -type nmap map[int]int -type nfunc func() + +type ( + nat []int + nmap map[int]int + nfunc func() +) func main() { var u1 []int @@ -11,14 +14,12 @@ func main() { var f func() var f2 nfunc - println(u1) println(n2) println(m) println(m2) println(f) println(f2) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno index 48599c922ba..09588bd5c10 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno @@ -1,10 +1,11 @@ package main -type nat []Word -type Word uint +type ( + nat []Word + Word uint +) func (n nat) add() nat { - return []Word{0} } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno index ba99f45adb3..f140d4b7291 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno @@ -1,10 +1,11 @@ package main -type nat []Word -type Word uint +type ( + nat []Word + Word uint +) func (n nat) add() []Word { - return nat{0} } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno index ba99f45adb3..f140d4b7291 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno @@ -1,10 +1,11 @@ package main -type nat []Word -type Word uint +type ( + nat []Word + Word uint +) func (n nat) add() []Word { - return nat{0} } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno index f2f4509e82a..2c41bbb0a97 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno @@ -1,18 +1,22 @@ package main -type nat []Word -type Word uint +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} diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno index 1efa2348052..a55e0606fec 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno @@ -5,8 +5,10 @@ import ( "fmt" ) -type word uint -type nat []word +type ( + word uint + nat []word +) var zero *Int @@ -16,7 +18,6 @@ type Int struct { } func main() { - zero = &Int{ abs: []word{0}, } @@ -184,7 +185,7 @@ func main() { // "BlockNode": null, // "Location": { // "File": "main.gno", -// "Line": "18", +// "Line": "20", // "Nonce": "0", // "PkgPath": "gno.land/r/test" // } diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno index 11186cdb200..0b304369764 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno @@ -12,9 +12,7 @@ func main() { func f(dopanic bool) (err error) { defer func() { if x := recover(); x != nil { - err = x.(error) - } }() q(dopanic) diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno index 007b613247c..2bdfdb474fe 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno @@ -1,7 +1,6 @@ package main func x() (int, int) { - return 1, 2 } @@ -10,7 +9,6 @@ func main() { a, b = x() println(a) println(b) - } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno index 19d6e38d8b2..d1439adfcae 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno @@ -9,7 +9,6 @@ func main() { var a uint a = x1() // should fail println("1") - } // Error: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno index 478a4b3b7a9..2a14a78f78c 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno @@ -13,7 +13,6 @@ func main() { a = x() println(a) - } // Error: diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno index 3f19e25caf5..cf5be970423 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno @@ -8,10 +8,8 @@ func x() interface{} { } func (n nat) double() nat { - m := append(n, n...) return m - } func main() { @@ -20,7 +18,6 @@ func main() { b := a.(nat).double().double() println(a) println(b) - } // Output: From 3643cc16507b4333d8a696d0d68a15a85ec63471 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:04:14 -0700 Subject: [PATCH 4/9] chore: update file name, comments and panic messages --- gnovm/pkg/gnolang/preprocess.go | 35 ++++++++++++------- gnovm/pkg/gnolang/types.go | 16 ++++----- gnovm/pkg/gnolang/values_string.go | 4 +-- gnovm/tests/file_test.go | 3 +- .../append_named_unnamed_type2_filetest.gno | 16 --------- .../append/named_unnamed_type2_filetest.gno | 16 +++++++++ ...t.gno => named_unnamed_type3_filetest.gno} | 5 +-- ...st.gno => named_unnamed_type_filetest.gno} | 5 +-- .../assign_unnamedtype0b_filetest.gno | 17 --------- ...est.gno => name_unnamed_type_filetest.gno} | 4 +-- .../declaredType0_filetest.gno | 0 .../declaredType0b_filetest.gno | 0 .../declaredType1_filetest.gno | 0 .../declaredType1b_filetest.gno | 0 .../declaredType2_filetest.gno | 3 ++ .../declaredType2b_filetest.gno | 0 .../declaredType3_filetest.gno | 0 .../declaredType3b_filetest.gno | 0 .../declaredType3c_filetest.gno | 0 .../declaredType3d_filetest.gno | 0 .../declaredType4_filetest.gno | 0 .../declaredType5_filetest.gno | 0 .../declaredType6_filetest.gno | 4 +-- .../declaredType6b_filetest.gno | 4 +-- .../assgin_interface2_filetest.gno | 0 .../assgin_interface_filetest.gno | 0 .../more/assgin_two_filetest.gno | 18 ++++++++++ .../assignment_filetest.gno | 0 .../convert_types1b_filetest.gno | 6 ++++ .../convert_types_filetest.gno | 0 .../cross_realm_compositelit_filetest.gno | 0 .../declaredtype2_filetest.gno | 0 .../default_value_filetest.gno | 0 .../errors2_filetest.gno | 0 .../method38d_filetest.gno | 0 .../method38e_filetest.gno | 0 .../method38e_filetest0.gno | 0 .../method38g_filetest.gno | 0 .../realm_compositelit_filetest.gno | 0 .../recover6_filetest.gno | 0 .../return2_filetest.gno | 0 .../return_interface1_filetest.gno | 2 +- .../return_interface_filetest.gno | 2 +- .../return_select_filetest.gno | 0 .../more_filetest/assgin_two_filetest.gno | 18 ---------- ...filetest.gno => unnamedtype0_filetest.gno} | 0 .../unnamedtype0b_filetest.gno | 17 +++++++++ ...filetest.gno => unnamedtype1_filetest.gno} | 0 ...iletest.gno => unnamedtype1a_filetest.gno} | 0 ...iletest.gno => unnamedtype1b_filetest.gno} | 0 ...iletest.gno => unnamedtype1c_filetest.gno} | 0 ...filetest.gno => unnamedtype2_filetest.gno} | 0 ...iletest.gno => unnamedtype2a_filetest.gno} | 0 ...iletest.gno => unnamedtype2b_filetest.gno} | 0 ...iletest.gno => unnamedtype2c_filetest.gno} | 0 ...filetest.gno => unnamedtype3_filetest.gno} | 0 ...iletest.gno => unnamedtype3a_filetest.gno} | 0 ...iletest.gno => unnamedtype3b_filetest.gno} | 0 ...iletest.gno => unnamedtype3c_filetest.gno} | 0 ...filetest.gno => unnamedtype4_filetest.gno} | 0 ...iletest.gno => unnamedtype4a_filetest.gno} | 0 ...iletest.gno => unnamedtype4b_filetest.gno} | 0 ...iletest.gno => unnamedtype4c_filetest.gno} | 0 ...filetest.gno => unnamedtype5_filetest.gno} | 0 ...iletest.gno => unnamedtype5a_filetest.gno} | 0 ...iletest.gno => unnamedtype5b_filetest.gno} | 0 ...iletest.gno => unnamedtype5c_filetest.gno} | 0 ...filetest.gno => unnamedtype6_filetest.gno} | 0 ...iletest.gno => unnamedtype6a_filetest.gno} | 0 ...iletest.gno => unnamedtype6b_filetest.gno} | 0 ...iletest.gno => unnamedtype6c_filetest.gno} | 0 ...filetest.gno => unnamedtype7_filetest.gno} | 0 72 files changed, 107 insertions(+), 88 deletions(-) delete mode 100644 gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno create mode 100644 gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type2_filetest.gno rename gnovm/tests/files/assign_unnamed_type/append/{append_named_unnamed_type3_filetest.gno => named_unnamed_type3_filetest.gno} (78%) rename gnovm/tests/files/assign_unnamed_type/append/{append_named_unnamed_type_filetest.gno => named_unnamed_type_filetest.gno} (91%) delete mode 100644 gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno rename gnovm/tests/files/assign_unnamed_type/copy/{copy_name_unnamed_filetest.gno => name_unnamed_type_filetest.gno} (87%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType0_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType0b_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType1_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType1b_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType2_filetest.gno (92%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType2b_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType3_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType3b_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType3c_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType3d_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType4_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType5_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType6_filetest.gno (54%) rename gnovm/tests/files/assign_unnamed_type/{declaredtype_method => method}/declaredType6b_filetest.gno (54%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/assgin_interface2_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/assgin_interface_filetest.gno (100%) create mode 100644 gnovm/tests/files/assign_unnamed_type/more/assgin_two_filetest.gno rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/assignment_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/convert_types1b_filetest.gno (64%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/convert_types_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/cross_realm_compositelit_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/declaredtype2_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/default_value_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/errors2_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/method38d_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/method38e_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/method38e_filetest0.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/method38g_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/realm_compositelit_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/recover6_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/return2_filetest.gno (100%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/return_interface1_filetest.gno (54%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/return_interface_filetest.gno (55%) rename gnovm/tests/files/assign_unnamed_type/{more_filetest => more}/return_select_filetest.gno (100%) delete mode 100644 gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype0_filetest.gno => unnamedtype0_filetest.gno} (100%) create mode 100644 gnovm/tests/files/assign_unnamed_type/unnamedtype0b_filetest.gno rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype1_filetest.gno => unnamedtype1_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype1a_filetest.gno => unnamedtype1a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype1b_filetest.gno => unnamedtype1b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype1c_filetest.gno => unnamedtype1c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype2_filetest.gno => unnamedtype2_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype2a_filetest.gno => unnamedtype2a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype2b_filetest.gno => unnamedtype2b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype2c_filetest.gno => unnamedtype2c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype3_filetest.gno => unnamedtype3_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype3a_filetest.gno => unnamedtype3a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype3b_filetest.gno => unnamedtype3b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype3c_filetest.gno => unnamedtype3c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype4_filetest.gno => unnamedtype4_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype4a_filetest.gno => unnamedtype4a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype4b_filetest.gno => unnamedtype4b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype4c_filetest.gno => unnamedtype4c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype5_filetest.gno => unnamedtype5_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype5a_filetest.gno => unnamedtype5a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype5b_filetest.gno => unnamedtype5b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype5c_filetest.gno => unnamedtype5c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype6_filetest.gno => unnamedtype6_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype6a_filetest.gno => unnamedtype6a_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype6b_filetest.gno => unnamedtype6b_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype6c_filetest.gno => unnamedtype6c_filetest.gno} (100%) rename gnovm/tests/files/assign_unnamed_type/{assign_unnamedtype7_filetest.gno => unnamedtype7_filetest.gno} (100%) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 5ce1420bd36..1ba9a16a87e 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1543,7 +1543,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { if dt, ok := st.(*DeclaredType); ok { mt = dt.Base.(*MapType) } else if mt, ok = st.(*MapType); !ok { - panic("should not happen") + panic("invalid index expression on MapType") } // re-definitions last.Define(lhs0, anyValue(mt.Value)) @@ -2341,34 +2341,45 @@ func checkOrConvertType(store Store, last BlockNode, x *Expr, t Type, autoNative } } // convert x to destination type t - cx := Expr(Call(constType(nil, t), *x)) - cx = Preprocess(store, last, cx).(Expr) - *x = cx + 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) - cx := Expr(Call(constType(nil, t), *x)) - cx = Preprocess(store, last, cx).(Expr) - *x = cx + convertType(store, last, x, t) } } } } -// Return true if we need to convert named and unnamed types in an assignment +// 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 } - // 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. + // no conversion case 1: the LHS is an interface _, c1 := t.(*InterfaceType) - // case2: TypeType is used in make() new() native uverse definition and TypeType.IsNamed() will panic on unexpected. + // no conversion case2: isNamedConversion is called within evaluating make() or new() + // (uverse functions) _, oktt := t.(*TypeType) _, oktt2 := xt.(*TypeType) diff --git a/gnovm/pkg/gnolang/types.go b/gnovm/pkg/gnolang/types.go index 3dc49635bf4..24ef62466f6 100644 --- a/gnovm/pkg/gnolang/types.go +++ b/gnovm/pkg/gnolang/types.go @@ -375,7 +375,7 @@ func (ft FieldType) GetPkgPath() string { } func (ft FieldType) IsNamed() bool { - panic("unexpected") + panic("FieldType is a pseudotype with no property called named") } // ---------------------------------------- @@ -893,7 +893,7 @@ func (pt *PackageType) GetPkgPath() string { } func (pt *PackageType) IsNamed() bool { - panic("unexpected") + panic("package types have no property called named") } // ---------------------------------------- @@ -1406,7 +1406,7 @@ func (tt *TypeType) GetPkgPath() string { } func (tt *TypeType) IsNamed() bool { - panic("unexpected") + panic("typeval types have no property called 'named'") } // ---------------------------------------- @@ -1900,7 +1900,7 @@ func (bt blockType) GetPkgPath() string { } func (bt blockType) IsNamed() bool { - panic("unexpected") + panic("blockType has no property called named") } // ---------------------------------------- @@ -1954,7 +1954,7 @@ func (tt *tupleType) GetPkgPath() string { } func (tt *tupleType) IsNamed() bool { - panic("unexpected") + panic("typleType has no property called named") } // ---------------------------------------- @@ -1977,15 +1977,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("unexpected") + panic("RefType has no property called named") } // ---------------------------------------- diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index 9c3b97d1f9f..1ed9afc8bb9 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -234,8 +234,8 @@ func (tv *TypedValue) Sprint(m *Machine) string { return sv.String() default: panic(fmt.Sprintf( - "unexpected slice type %v", - reflect.TypeOf(tv.V))) + "unexpected slice type %T", + tv.V)) } case *StructType: return tv.V.(*StructValue).String() diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 4e926191bb8..ee8782503e2 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -3,6 +3,7 @@ package tests import ( "flag" "io/fs" + "os" "path" "path/filepath" "strings" @@ -57,7 +58,7 @@ func runFileTests(t *testing.T, baseDir string, ignore []string, opts ...RunFile var name string for _, file := range files { path = file.path - name = file.DirEntry.Name() + name = strings.TrimPrefix(file.path, baseDir+string(os.PathSeparator)) t.Run(name, func(t *testing.T) { runFileTest(t, path, opts...) }) diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno deleted file mode 100644 index cd8764845b1..00000000000 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno +++ /dev/null @@ -1,16 +0,0 @@ -package main - -type ( - nat []int - nat64 []int64 -) - -func main() { - nlist := nat{0} - n64list := nat64{1} - a := append(n64list, nlist...) - println(a) -} - -// Error: -// main/files/assign_unnamed_type/append/append_named_unnamed_type2_filetest.gno:11: cannot use int as int64 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/append_named_unnamed_type3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno similarity index 78% rename from gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno index ff342ee7aa9..912aedb468d 100644 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type3_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type3_filetest.gno @@ -3,11 +3,12 @@ package main type nat []int func main() { - nlist := nat{0} - ulist := []int{1} + var nlist = nat{0} + var ulist = []int{1} a := append(nlist, nlist[0], ulist[0]) println(a) + } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno similarity index 91% rename from gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno index e5df7ede65a..7c37919f514 100644 --- a/gnovm/tests/files/assign_unnamed_type/append/append_named_unnamed_type_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/append/named_unnamed_type_filetest.gno @@ -3,8 +3,8 @@ package main type nat []int func main() { - nlist := nat{0} - ulist := []int{1} + var nlist = nat{0} + var ulist = []int{1} var n int = 3 a := append(nlist, n) @@ -23,6 +23,7 @@ func main() { println(b) println(c) println(d) + } // Output: diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno deleted file mode 100644 index f9feb479201..00000000000 --- a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0b_filetest.gno +++ /dev/null @@ -1,17 +0,0 @@ -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/assign_unnamedtype0b_filetest.gno:11: cannot use main.word as int without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno b/gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno similarity index 87% rename from gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno index 525e28f2081..0351f4f62db 100644 --- a/gnovm/tests/files/assign_unnamed_type/copy/copy_name_unnamed_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/copy/name_unnamed_type_filetest.gno @@ -3,8 +3,8 @@ package main type nat []int func main() { - nlist := nat{0} - ulist := []int{1} + var nlist = nat{0} + var ulist = []int{1} copy(nlist, ulist) diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType0_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType0_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType0b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType0b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType0b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType1_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType1_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType1b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType1b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType1b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno similarity index 92% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno index 3498cdf3f16..71d3601ebef 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType2_filetest.gno @@ -22,3 +22,6 @@ func main() { println(r.add()) } + +// Output: +// true diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType2b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType2b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType2b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType3_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType3b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType3c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType3d_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType3d_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType3d_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType4_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType4_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType4_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType5_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType5_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType5_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno similarity index 54% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno index a6953db5cef..5d994352f35 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType6_filetest.gno @@ -12,11 +12,9 @@ func (n nat) add() bool { func main() { var abs nat - abs = []c{0} - println(abs.add()) } // Error: -// main/files/assign_unnamed_type/declaredtype_method/declaredType6_filetest.gno:16: cannot use main.c as main.word without explicit conversion +// 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/declaredtype_method/declaredType6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno similarity index 54% rename from gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno index 382859b32d2..88b3203a805 100644 --- a/gnovm/tests/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/method/declaredType6b_filetest.gno @@ -12,11 +12,9 @@ func (n nat) add() bool { func main() { var abs nat - abs = []uint{0} - println(abs.add()) } // Error: -// main/files/assign_unnamed_type/declaredtype_method/declaredType6b_filetest.gno:16: cannot use uint as main.word without explicit conversion +// 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_filetest/assgin_interface2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface2_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/assgin_interface2_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assgin_interface_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_interface_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/assgin_interface_filetest.gno 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_filetest/assignment_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/assignment_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/assignment_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/assignment_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno similarity index 64% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno index 983a4ab073d..aeaabfedd1d 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types1b_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more/convert_types1b_filetest.gno @@ -16,3 +16,9 @@ func main() { 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_filetest/convert_types_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/convert_types_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/convert_types_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/convert_types_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/cross_realm_compositelit_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/cross_realm_compositelit_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/cross_realm_compositelit_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/declaredtype2_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/declaredtype2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/declaredtype2_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/default_value_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/default_value_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/default_value_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/errors2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/errors2_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/errors2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/errors2_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38d_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/method38d_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/method38d_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/method38e_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno b/gnovm/tests/files/assign_unnamed_type/more/method38e_filetest0.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/method38e_filetest0.gno rename to gnovm/tests/files/assign_unnamed_type/more/method38e_filetest0.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/method38g_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/method38g_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/method38g_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/realm_compositelit_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/recover6_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/recover6_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/recover6_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return2_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/return2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/return2_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno similarity index 54% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno index d1439adfcae..9395426cfc8 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more/return_interface1_filetest.gno @@ -12,4 +12,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/more_filetest/return_interface1_filetest.gno:10: cannot use interface{} as uint +// 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_filetest/return_interface_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno similarity index 55% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno index 2a14a78f78c..8b5fdd7c728 100644 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more/return_interface_filetest.gno @@ -16,4 +16,4 @@ func main() { } // Error: -// main/files/assign_unnamed_type/more_filetest/return_interface_filetest.gno:13: cannot use interface{} as []int +// 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_filetest/return_select_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/return_select_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/more_filetest/return_select_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/more/return_select_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno deleted file mode 100644 index e9abfc4dd11..00000000000 --- a/gnovm/tests/files/assign_unnamed_type/more_filetest/assgin_two_filetest.gno +++ /dev/null @@ -1,18 +0,0 @@ -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_filetest/assgin_two_filetest.gno:11: cannot use main.nat2 as main.nat without explicit conversion diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype0_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype0_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype0_filetest.gno 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/assign_unnamedtype1_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype1_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype1a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype1b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype1c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype1c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype1c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype2_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype2a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype2b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype2c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype2c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype2c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype3_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype3a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype3b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype3c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype3c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype3c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype4_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype4a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype4b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype4c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype4c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype4c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype5b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype5c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype5c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype6_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6a_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6a_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype6a_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6b_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6b_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype6b_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype6c_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype6c_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype6c_filetest.gno diff --git a/gnovm/tests/files/assign_unnamed_type/assign_unnamedtype7_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype7_filetest.gno similarity index 100% rename from gnovm/tests/files/assign_unnamed_type/assign_unnamedtype7_filetest.gno rename to gnovm/tests/files/assign_unnamed_type/unnamedtype7_filetest.gno From 43cab86a5866dabb7a30ee5843a7c9fc67d3aa75 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:58:45 -0700 Subject: [PATCH 5/9] merged new value string print --- gnovm/pkg/gnolang/values_string.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index 34187e32879..274cea0fa56 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -374,7 +374,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 From 29b6e23893781e5ceb9933b45088289272e987c6 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:30:33 -0700 Subject: [PATCH 6/9] chore: update the tests --- gnovm/pkg/gnolang/uverse_test.go | 4 +- .../more/realm_compositelit_filetest.gno | 2 + gnovm/tests/files/print1.gno | 2 +- gnovm/tests/files/zrealm_tests0.gno | 78 ++----------------- 4 files changed, 13 insertions(+), 73 deletions(-) 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/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno b/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno index a55e0606fec..6549d1824ed 100644 --- a/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/more/realm_compositelit_filetest.gno @@ -179,6 +179,8 @@ func main() { // "FileName": "main.gno", // "IsMethod": false, // "Name": "main", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "gno.land/r/test", // "Source": { // "@type": "/gno.RefNode", 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 e6371221967..9c8c1068643 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -257,76 +257,8 @@ func main() { // "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", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", // "Source": { // "@type": "/gno.RefNode", @@ -696,6 +628,8 @@ func main() { // "FileName": "realm_compositelit.gno", // "IsMethod": false, // "Name": "GetZeroType", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", // "Source": { // "@type": "/gno.RefNode", @@ -750,6 +684,8 @@ func main() { // "FileName": "realm_method38d.gno", // "IsMethod": false, // "Name": "GetAbs", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", // "Source": { // "@type": "/gno.RefNode", @@ -804,6 +740,8 @@ func main() { // "FileName": "realm_method38d.gno", // "IsMethod": false, // "Name": "AbsAdd", +// "NativeName": "", +// "NativePkg": "", // "PkgPath": "gno.land/r/demo/tests", // "Source": { // "@type": "/gno.RefNode", From 383645b0692ebba51f59e948c6cb8bf8e5c86a15 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:44:03 -0600 Subject: [PATCH 7/9] chore: add panic message --- gnovm/pkg/gnolang/preprocess.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 40ec60ca515..793dd9e5544 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1585,7 +1585,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { var mt *MapType st := evalStaticTypeOf(store, last, cx.X) if dt, ok := st.(*DeclaredType); ok { - mt = dt.Base.(*MapType) + if mt, ok = dt.Base.(*MapType); !ok { + s := fmt.Sprintf("the base of the %s is invalid, it should be MapType", dt.Name) + panic(s) + } } else if mt, ok = st.(*MapType); !ok { panic("invalid index expression on MapType") } From 6c272377246ac7f79dcc23fdad957e4786572fb0 Mon Sep 17 00:00:00 2001 From: piux2 <90544084+piux2@users.noreply.github.com> Date: Thu, 30 May 2024 14:37:25 -0700 Subject: [PATCH 8/9] chore: using baseOf() and one more test --- gnovm/pkg/gnolang/preprocess.go | 22 ++++++++----------- .../files/assign_unnamed_type/type40.gno | 20 +++++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 gnovm/tests/files/assign_unnamed_type/type40.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 793dd9e5544..fd20a598b1e 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -1583,14 +1583,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node { lhs1 := n.Lhs[1].(*NameExpr).Name var mt *MapType - st := evalStaticTypeOf(store, last, cx.X) - if dt, ok := st.(*DeclaredType); ok { - if mt, ok = dt.Base.(*MapType); !ok { - s := fmt.Sprintf("the base of the %s is invalid, it should be MapType", dt.Name) - panic(s) - } - } else if mt, ok = st.(*MapType); !ok { - panic("invalid index expression on MapType") + dt := evalStaticTypeOf(store, last, cx.X) + mt, ok := baseOf(dt).(*MapType) + if !ok { + panic(fmt.Sprintf("invalid index expression on %T", dt)) } // re-definitions last.Define(lhs0, anyValue(mt.Value)) @@ -2416,11 +2412,11 @@ func convertType(store Store, last BlockNode, x *Expr, t Type) { // 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 - +// +// 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 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 From b2180d56153109ad44c9c3793622cbd323c3f89c Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Fri, 31 May 2024 17:33:40 +0200 Subject: [PATCH 9/9] fix golden test, skip "extern" directory --- gnovm/tests/file_test.go | 3 +++ gnovm/tests/files/zrealm_tests0.gno | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gnovm/tests/file_test.go b/gnovm/tests/file_test.go index 5748c66ea8a..4313fd88645 100644 --- a/gnovm/tests/file_test.go +++ b/gnovm/tests/file_test.go @@ -75,6 +75,9 @@ func readFiles(t *testing.T, dir string) ([]testFile, 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) diff --git a/gnovm/tests/files/zrealm_tests0.gno b/gnovm/tests/files/zrealm_tests0.gno index 28006afe0c2..d68c1f652f7 100644 --- a/gnovm/tests/files/zrealm_tests0.gno +++ b/gnovm/tests/files/zrealm_tests0.gno @@ -939,7 +939,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1077,7 +1077,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false, @@ -1123,7 +1123,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:4" +// "ObjectID": "0ffe7732b4d549b4cf9ec18bd68641cd2c75ad0a:6" // }, // "FileName": "tests.gno", // "IsMethod": false,