Skip to content

Commit a938467

Browse files
Fix a bug in feature resolution for the sister fields created for extensions
1 parent 1af8454 commit a938467

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/object.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,18 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures() {
197197
} else if (this.partOf instanceof OneOf) {
198198
var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
199199
this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
200+
} else if (this.declaringField) {
201+
// Skip feature resolution of sister fields.
200202
} else if (this.parent) {
201203
var parentFeaturesCopy = Object.assign({}, this.parent._features);
202204
this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
203205
} else {
204206
this._features = Object.assign({}, protoFeatures);
205207
}
208+
if (this.extensionField) {
209+
// Sister fields should have the same features as their extensions.
210+
this.extensionField._features = this._features;
211+
}
206212
};
207213

208214
/**

tests/feature_resolution_editions.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,37 @@ tape.test("feature resolution editions precedence", function(test) {
437437
});
438438
});
439439

440+
tape.test("feature resolution extension sister", function(test) {
441+
var root = protobuf.parse(`edition = "2023";
442+
message A {
443+
message B {
444+
message One {
445+
extensions 1000 to max;
446+
reserved 900 to 999, 899, "a", 'b';
447+
}
448+
}
449+
message C {
450+
option features.repeated_field_encoding = EXPANDED;
451+
message Two {
452+
extend B.One {
453+
repeated int32 ext = 1000 [features.fake = 2];
454+
}
455+
}
456+
}
457+
}`).root.resolveAll();
458+
var extension = root.lookup("A.C.Two").nested.ext;
459+
var sister = root.lookup("A.B.One").fields[".A.C.Two.ext"];
460+
461+
test.notOk(extension.packed);
462+
test.notOk(sister.packed);
463+
test.equal(extension._features.repeated_field_encoding, "EXPANDED");
464+
test.equal(extension._features.fake, 2);
465+
test.equal(sister._features.repeated_field_encoding, "EXPANDED");
466+
test.equal(sister._features.fake, 2);
467+
468+
test.end();
469+
});
470+
440471
tape.test("feature resolution inferred proto2 repeated encoding", function(test) {
441472
var root = protobuf.parse(`syntax = "proto2";
442473
message Message {

0 commit comments

Comments
 (0)