microsoft / microsoft/typespec

[Bug]: Confusion on field annotation for inherited models (protobuf)

Open
#3,266 0 comments 0 reactions 1 assignee Claimed by @witemple-msft View on GitHub
bug emitter:protobuf triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Describe the bug

The annotation of fields for inherited models targeting a protobuf emitter is a bit confusing.
```typespec
import "@typespec/protobuf";

using TypeSpec.Protobuf;

@package({
name: "test",
})
namespace test;

model Parent {
id: int64
}

model Child1 is Parent {} // Not working
@@field(Child1.id, 1);

model Child2 extends Parent {} // Outputs empty `message`
@@field(Child2.id, 1);

model Child3 { // Correct
...Parent
}
@@field(Child3.id, 1);
```
I couldn't figure out from the documentation why only `Child3` would yield the correct result. From what I've tested, it seems that for `Child1` and `Child2` there is a failure to recognize and tag the `id` field appropriately.

This is especially confusing since I'm using this for generating `openapi3` specs (through `@typespec/http`) as well, with syntax of `Child1` working as expected.

Any insights as to whether this is a bug or just a misunderstanding of the language would be appreciated thanks !

### Reproduction

https://typespec.io/playground?options=%7B%22linterRuleSet%22%3A%7B%22extends%22%3A%5B%22%40typespec%2Fhttp%2Fall%22%5D%7D%7D&c=aW1wb3J0ICJAdHlwZXNwZWMvcHJvdG9idWYiOwoKdXNpbmcgVHlwZVNwZWMuUMcbOwoKQHBhY2thZ2UoewogIG5hbWU6ICJ0ZXN0IiwKfSkKxBFzcGFjZSDEFDsKCm1vZGVsIFBhcmVudCB7CglpZDogaW50NjQKfcgdQ2hpbGQxIGlzySd9CkBAZmllbGQoxhwuaWQsIDEpyU%2FFFjIgZXh0ZW5k2Tcy1Tcz5ACGLi4uxjUKzzQzyDQ%3D&e=%40typespec%2Fprotobuf

### Checklist

- [X] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [X] Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/Microsoft/typespec/discussions).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.