Open osa1 opened 2 years ago
Repro:
syntax = "proto3";
message Test {
map<int32, int32> map_field = 1;
repeated int32 repeated_field = 2;
NestedMsg message_field = 3;
}
message NestedMsg {
int32 int_field = 1;
}
import '../test.pb.dart';
import 'package:protobuf/protobuf.dart';
void main() {
final msg = (Test().freeze()) as Test;
final map = (msg.getDefaultForField(1)) as PbMap;
map[1] = 2; // works
print('OK');
final nestedMsg = msg.getDefaultForField(3) as NestedMsg;
try {
nestedMsg.intField = 123; // fails as expected
} catch (e) {
print('OK');
}
final list = (msg.getDefaultForField(2)) as PbList;
try {
list.add(1); // fails as expected
} catch (e) {
print('OK');
}
}
https://github.com/google/protobuf.dart/blob/6a3e7f024a46b9353fd172abe2b80125244cae45/protobuf/lib/src/protobuf/field_info.dart#L160-L165
which for map fields calls https://github.com/google/protobuf.dart/blob/6a3e7f024a46b9353fd172abe2b80125244cae45/protobuf/lib/src/protobuf/field_info.dart#L282
which uses
PbMap
, instead ofPbMap.unmodifiable
.