8000 internal/encoding/gotypes: embedded disjunction translates to empty struct · Issue #3962 · cue-lang/cue · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
internal/encoding/gotypes: embedded disjunction translates to empty struct #3962
Open
@rogpeppe

Description

@rogpeppe

What version of CUE are you using (cue version)?

250524b0d6e0a2d64e2be220d55334ef62d65df6

Does this issue reproduce with the latest stable release?

Yes

What did you do?

Generate some CUE from a protobuf definition, then generate Go types from that:

exec cue import -I . x.proto
exec cat x.cue
exec cue exp gengotypes
grep commonField cue_types_v1_gen.go

-- foo.json --
{
	"x": {
		"something": true
	}
}
-- x.proto --
syntax = "proto3";

package something.v1;

message T {
  string commonField = 1;
  oneof foo {
    string foo = 2;
    int64 bar = 3;
  }
}

What did you expect to see?

A passing test: at least the common fields from the protobuf message should be
present in the Go code.

What did you see instead?

Instead, all fields are omitted. One reason for this is that cue.Value.Fields will return an error in this case because the fields are not all known. Some new API or option is probably required to enable gengotypes to do its job properly here.

> exec cue import -I . x.proto
> exec cat x.cue
[stdout]
package v1

#T: {
	commonField?: string @protobuf(1,string)
	{} | {
		foo: string @protobuf(2,string)
	} | {
		bar: int64 @protobuf(3,int64)
	}
}
> exec cue exp gengotypes
> grep commonField cue_types_v1_gen.go
[cue_types_v1_gen.go]
// Code generated by "cue exp gengotypes"; DO NOT EDIT.

package v1

type T struct {
}

FAIL: /tmp/x.txtar:4: no match for `commonField` found in cue_types_v1_gen.go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0