Skip to content

Commit

Permalink
Merge pull request #95 from grafana/fix-structs-with-only-one-ref
Browse files Browse the repository at this point in the history
Fix structs with only one reference
  • Loading branch information
sam boyer authored Apr 4, 2023
2 parents 7257adf + 63024ba commit 7d314ea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func TestGenerateWithImports(t *testing.T) {
ToDo: map[string]string{
"imports/oneref_verbose": "Figure out how to disambiguate struct literals from the struct-with-braces-and-one-element case",
"imports/struct_shorthand": "Shorthand struct notation is currently unsupported, needs fixing",
"imports/single_embed": "Single-item struct embeds should be treated as just another interface to compose, but get confused with references - #60",
"imports/inline_comments": "Inline comments do not appear be retrievable from cue.Value.Doc()",
"imports/nulltype": "null types are not handled correctly",
},
Expand Down
2 changes: 1 addition & 1 deletion generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ func valError(v cue.Value, format string, args ...interface{}) error {
func refAsInterface(v cue.Value) (ts.Expr, error) {
// Bail out right away if the value isn't a reference
op, dvals := v.Expr()
if !isReference(v) || op != cue.SelectorOp {
if !isReference(v) && op != cue.SelectorOp {
return nil, fmt.Errorf("not a reference")
}

Expand Down
5 changes: 3 additions & 2 deletions testdata/imports/single_embed.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export interface Attrib {
ImportedInner: {
nestedval: string;
};
importedNoAttribField: string;
importedAttribField: string;
}

export interface Wrapped extends Attrib {}
export interface dep.Wrapped extends dep.Attrib {}

export interface DepWrapped extends dep.Attrib {}

0 comments on commit 7d314ea

Please sign in to comment.