New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cc2 #6600
base: main
Are you sure you want to change the base?
cc2 #6600
Conversation
d43b42e
to
a175295
Compare
'WriteValue(EncodableValue(std::any_cast<${customType.name}>(*custom_value).ToEncodableList()), stream);'); | ||
} else if (customType.type == CustomTypes.customEnum) { | ||
indent.writeln( | ||
'WriteValue(EncodableValue(std::any_cast<int>(*custom_value)), stream);'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WriteValue(EncodableValue(static_cast<int>(std::any_cast<${customType.name}>(*custom_value))), stream);
(Not doing as a GitHub code suggestion since I'm not sure which of my email addresses committing it would use, and I don't want to blow up the CLA check.)
: std::make_optional<AnEnum>( | ||
static_cast<AnEnum>(an_enum_arg_value)); | ||
const auto* an_enum_arg = &(std::any_cast<const AnEnum&>( | ||
std::get<CustomEncodableValue>(encodable_an_enum_arg))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bad variant access error is coming from this pattern: if the arg's value is null, then encodable_an_enum_arg
isn't a CustomEncodableValue
at all, it's a monotype (i.e., IsNull()
is true). So you need to check IsNull()
before doing a std::get instead of after, or you need to use a get_if<CustomEncodableValue>(&encodable_an_enum_arg)
and then if that's null, pass null, and if it's not not, do the any-cast. (The thing that tripped me up in my first attempt to write a fix for this is that you can't any_cast
a CustomEncodableValue*
because of how implicit conversions work, so you'll need to do some gymnastics with a value variable like before I think.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of clunky, but the only way I can find to do it in a single statement involves a pointer to a reference that I can't prove to myself has a lifetime beyond that statement, and I'd rather the code be longer than have undefined behavior...
AnEnum an_enum_arg_value;
const AnEnum* an_enum_arg = nullptr;
if (!encodable_an_enum_arg.IsNull()) {
an_enum_arg_value = std::any_cast<AnEnum>(std::get<CustomEncodableValue>(encodable_an_enum_arg));
an_enum_arg = &an_enum_arg_value;
}
...EchoNullableEnum(an_enum_arg);
wip
fixes flutter/flutter#147454
fixes flutter/flutter#147127
fixes flutter/flutter#147587
fixes flutter/flutter#148065