Commit 8fcde2ca authored by Jon Skeet's avatar Jon Skeet

Fix oneof behaviour in the face of default values.

parent ca2adbd5
...@@ -137,8 +137,6 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() { ...@@ -137,8 +137,6 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {
} }
void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) { void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
// TODO(jonskeet): What should foo.OneofIntField = 0; do? Clear the oneof?
// Currently foo.OneOfStringField = null will clear the oneof, but foo.OneOfStringField = "" won't. Ick.
AddDeprecatedFlag(printer); AddDeprecatedFlag(printer);
printer->Print( printer->Print(
variables_, variables_,
...@@ -148,15 +146,14 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) { ...@@ -148,15 +146,14 @@ void PrimitiveOneofFieldGenerator::GenerateMembers(io::Printer* printer) {
if (is_value_type) { if (is_value_type) {
printer->Print( printer->Print(
variables_, variables_,
" $oneof_name$_ = value;\n" " $oneof_name$_ = value;\n");
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
} else { } else {
printer->Print( printer->Print(
variables_, variables_,
" $oneof_name$_ = value ?? $default_value$;\n" " $oneof_name$_ = value ?? $default_value$;\n");
" $oneof_name$Case_ = value == null ? $oneof_property_name$OneofCase.None : $oneof_property_name$OneofCase.$property_name$;\n");
} }
printer->Print( printer->Print(
" $oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n"
" }\n" " }\n"
"}\n"); "}\n");
} }
...@@ -167,11 +164,9 @@ void PrimitiveOneofFieldGenerator::WriteToString(io::Printer* printer) { ...@@ -167,11 +164,9 @@ void PrimitiveOneofFieldGenerator::WriteToString(io::Printer* printer) {
} }
void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) { void PrimitiveOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) {
// TODO(jonskeet): What if the value we read is the default value for the type?
printer->Print( printer->Print(
variables_, variables_,
"$oneof_name$_ = input.Read$capitalized_type_name$()\n;" "$property_name$ = input.Read$capitalized_type_name$()\n;");
"$oneof_name$Case_ = $oneof_property_name$OneofCase.$property_name$;\n");
} }
} // namespace csharp } // namespace csharp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment