-
Notifications
You must be signed in to change notification settings - Fork 566
Feature/1001 avoid segfault on empty literal mergestring #1012
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
Feature/1001 avoid segfault on empty literal mergestring #1012
Conversation
Thank you for great contribution and great testcase! |
ast/desugar/Desugar.cc
Outdated
@@ -94,7 +94,10 @@ unique_ptr<Expression> mergeStrings(DesugarContext dctx, core::Loc loc, | |||
loc, | |||
dctx.ctx.state.enterNameUTF8(fmt::format( | |||
"{}", fmt::map_join(stringsAccumulated.begin(), stringsAccumulated.end(), "", [&](const auto &expr) { | |||
return cast_tree<Literal>(expr.get())->asString(dctx.ctx).data(dctx.ctx)->shortName(dctx.ctx); | |||
if (isa_tree<EmptyTree>(expr.get())) | |||
return std::basic_string_view(""); |
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.
""sv
will make it more readable.
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.
Super minor nitpick, otherwise LGTM
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.
lgtm pending the two comments
ast/desugar/test/desugar_test.cc
Outdated
auto ast = sorbet::parser::Parser::run(gs, "<test>", "\"#{}:\""); | ||
sorbet::core::MutableContext ctx(gs, sorbet::core::Symbols::root()); | ||
auto o1 = sorbet::ast::desugar::node2Tree(ctx, move(ast)); | ||
} |
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 test case is redundant with the test/testdata
test, and the other one is shorter and easier to grep for.
Do you mind deleting this?
@DarkDimius @jez |
Thank you! Kicking off CI, will merge when it passes! |
Motivation
close #1001
Test plan
See included automated tests.