Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (c *Context) LookupByValue(tv scode.Bytes) (Type, error) {
if rest == nil {
return nil, errors.New("bad type value encoding")
}
c.toValue[typ] = tv
c.toValue[typ] = slices.Clone(tv)
c.toType[string(tv)] = typ
return typ, nil
}
Expand Down
15 changes: 15 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ import (
"github.com/stretchr/testify/require"
)

func TestContextLookupByValueAndLookupTypeValue(t *testing.T) {
sctx := super.NewContext()
recType := sctx.MustLookupTypeRecord(nil)

tv := super.EncodeTypeValue(recType)
typ, err := sctx.LookupByValue(tv)
require.NoError(t, err)
assert.Equal(t, recType, typ)

// Overwriting tv should not affect sctx's cached type value for recType.
super.AppendTypeValue(tv[:0], super.TypeNull)
val := sctx.LookupTypeValue(recType)
assert.Exactly(t, super.EncodeTypeValue(recType), val.Bytes())
}

func TestContextLookupTypeNamedErrors(t *testing.T) {
sctx := super.NewContext()

Expand Down
Loading