Skip to content
Closed
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
3 changes: 3 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (c *Context) LookupByName(name string) *TypeNamed {
// name to that named type. LookupTypeNamed returns an error if name is not a
// valid UTF-8 string or is a primitive type name.
func (c *Context) LookupTypeNamed(name string, inner Type) (*TypeNamed, error) {
if n, ok := inner.(*TypeNamed); ok {
return nil, fmt.Errorf("can't create named type %q from existing named type %q", name, n.Name)
}
if !utf8.ValidString(name) {
return nil, fmt.Errorf("bad type name %q: invalid UTF-8", name)
}
Expand Down
6 changes: 6 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func TestContextLookupTypeNamedErrors(t *testing.T) {

_, err = sctx.LookupTypeNamed("null", super.TypeNull)
assert.EqualError(t, err, `bad type name "null": primitive type name`)

typ, err := sctx.LookupTypeNamed("n1", super.TypeNull)
require.NoError(t, err)
_, err = sctx.LookupTypeNamed("n2", typ)
assert.EqualError(t, err, `can't create named type "n2" from existing named type "n1"`)

}

func TestContextLookupTypeNamedAndLookupTypeDef(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions sup/ztests/named.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spq: pass

input-flags: -i sup

input: |
1::n1=(n2=int64)

error: |
can't create named type "n1" from existing named type "n2"
Loading