We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This potential issue was uncovered in #2325.
Quite simply, the following code does not panic:
package amino_test import ( "reflect" "testing" "github.com/stretchr/testify/assert" amino "github.com/gnolang/gno/tm2/pkg/amino" "github.com/gnolang/gno/tm2/pkg/amino/tests" ) func TestDupNamesMustPanic(t *testing.T) { assert.Panics(t, func() { amino.NewPackage( reflect.TypeOf(tests.EmptyStruct{}).PkgPath(), "amino_test", amino.GetCallersDirname(), ).WithTypes( tests.EmptyStruct{}, "A", tests.PrimitivesStruct{}, "B", tests.ShortArraysStruct{}, "A", // Same name ) } }
Since codec_test.go has the following line a panic should be expected here:
// XXX Test registering duplicate names or concrete types not in a package.
Existing code for WithTypes prepares a pkg.Types which can just be iterated before returning.
WithTypes
pkg.Types
gno/tm2/pkg/amino/pkg/pkg.go
Lines 126 to 187 in 5541e35
The following actually fixes the test in #2325:
(...) pkg.Types = append(pkg.Types, lastType) } // APPENDED HERE ------------------------------------------------------- // Forbid duplicate names for i, t := range pkg.Types { if t.Name == "" { continue } for j := i + 1; j < len(pkg.Types); j++ { if pkg.Types[j].Name == t.Name { panic(fmt.Errorf("type name %s is already registered", t.Name)) } } } // ------------------------------------------------------------------------^^^ return pkg }
The text was updated successfully, but these errors were encountered:
e352770
Successfully merging a pull request may close this issue.
amino.WithTypes admits types with the same name
This potential issue was uncovered in #2325.
Description
Quite simply, the following code does not panic:
Expected behaviour
Since codec_test.go has the following line a panic should be expected here:
// XXX Test registering duplicate names or concrete types not in a package.
Proposed solution
Existing code for
WithTypes
prepares apkg.Types
which can just be iterated before returning.gno/tm2/pkg/amino/pkg/pkg.go
Lines 126 to 187 in 5541e35
The following actually fixes the test in #2325:
The text was updated successfully, but these errors were encountered: