Skip to content

Commit

Permalink
fix: add imports for type parameter datarefs (#889)
Browse files Browse the repository at this point in the history
They were missing in the code gen for clients
  • Loading branch information
wesbillman authored Feb 7, 2024
1 parent 07c7804 commit a2a55a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backend/schema/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ func (m *Module) Imports() []string {
if n.Module != "" && n.Module != m.Name {
imports[n.Module] = true
}
// add imports for type parameters DataRefs as well
for _, p := range n.TypeParameters {
if p, ok := p.(*DataRef); ok {
if p.Module != "" && p.Module != m.Name {
imports[p.Module] = true
}
}
}

case *VerbRef:
if n.Module != "" && n.Module != m.Name {
Expand Down
6 changes: 5 additions & 1 deletion backend/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,19 @@ func normaliseString(s string) string {
func TestImports(t *testing.T) {
input := `
module test {
data Generic<T> {
value T
}
data Data {
ref other.Data
ref another.Data
ref Generic<new.Data>
}
}
`
schema, err := ParseModuleString("", input)
assert.NoError(t, err)
assert.Equal(t, []string{"another", "other"}, schema.Imports())
assert.Equal(t, []string{"another", "new", "other"}, schema.Imports())
}

func TestVisit(t *testing.T) {
Expand Down

0 comments on commit a2a55a8

Please sign in to comment.