@@ -4473,31 +4473,54 @@ unique_ptr<parser::Node> Translator::translateCallWithBlock(pm_node_t *prismBloc
44734473 body = this ->enterBlockContext ().translate (prismLambdaNode->body );
44744474 }
44754475
4476- unique_ptr<parser::Node> parametersNode;
4476+ // Special case NumParams for lambda nodes
44774477 if (prismParametersNode != nullptr ) {
4478- switch (PM_NODE_TYPE (prismParametersNode)) {
4479- case PM_NUMBERED_PARAMETERS_NODE: {
4480- if (PM_NODE_TYPE_P (prismBlockOrLambdaNode, PM_BLOCK_NODE)) {
4481- auto prismBlockNode = down_cast<pm_block_node>(prismBlockOrLambdaNode);
4482- parametersNode = translate (prismBlockNode->parameters );
4483- } else {
4484- ENFORCE (PM_NODE_TYPE_P (prismBlockOrLambdaNode, PM_LAMBDA_NODE))
4485- auto prismLambdaNode = down_cast<pm_lambda_node>(prismBlockOrLambdaNode);
4486- prismLambdaNode->parameters ->location = (pm_location_t ){.start = prismLambdaNode->operator_loc .end ,
4487- .end = prismLambdaNode->operator_loc .end };
4488- parametersNode = translate (prismLambdaNode->parameters );
4489- body = this ->enterBlockContext ().translate (prismLambdaNode->body );
4490- }
4491-
4492- break ;
4493- }
4494- default : {
4495- parametersNode = translate (prismParametersNode);
4496- break ;
4497- }
4478+ if (PM_NODE_TYPE_P (prismBlockOrLambdaNode, PM_LAMBDA_NODE) && prismParametersNode != nullptr &&
4479+ PM_NODE_TYPE_P (prismParametersNode, PM_NUMBERED_PARAMETERS_NODE)) {
4480+ auto prismLambdaNode = down_cast<pm_lambda_node>(prismBlockOrLambdaNode);
4481+ prismLambdaNode->parameters ->location =
4482+ (pm_location_t ){.start = prismLambdaNode->operator_loc .end , .end = prismLambdaNode->operator_loc .end };
44984483 }
44994484 }
45004485
4486+ auto parametersNode = translate (prismParametersNode);
4487+
4488+ // switch (PM_NODE_TYPE(prismParametersNode)) {
4489+ // case PM_NUMBERED_PARAMETERS_NODE: {
4490+ // if (PM_NODE_TYPE_P(prismBlockOrLambdaNode, PM_BLOCK_NODE)) {
4491+ // auto prismBlockNode = down_cast<pm_block_node>(prismBlockOrLambdaNode);
4492+ // parametersNode = translate(prismBlockNode->parameters);
4493+ // } else {
4494+ // ENFORCE(PM_NODE_TYPE_P(prismBlockOrLambdaNode, PM_LAMBDA_NODE))
4495+ // auto prismLambdaNode = down_cast<pm_lambda_node>(prismBlockOrLambdaNode);
4496+ // prismLambdaNode->parameters->location = (pm_location_t){.start =
4497+ // prismLambdaNode->operator_loc.end,
4498+ // .end =
4499+ // prismLambdaNode->operator_loc.end};
4500+ // parametersNode = translate(prismLambdaNode->parameters);
4501+ // body = this->enterBlockContext().translate(prismLambdaNode->body);
4502+ // }
4503+
4504+ // break;
4505+ // }
4506+ // default: {
4507+ // parametersNode = translate(prismParametersNode);
4508+ // break;
4509+ // }
4510+
4511+ // case PM_PARAMETERS_NODE: {
4512+ // auto regularParametersNode = down_cast<pm_parameters_node>(prismParametersNode);
4513+ // std::tie(parametersNode, std::ignore) =
4514+ // translateParametersNode(regularParametersNode,
4515+ // translateLoc(regularParametersNode->base.location));
4516+ // break;
4517+ // }
4518+ // default: {
4519+ // unreachable("Unexpected PM_NODE_TYPE in translateCallWithBlock(): {}",
4520+ // PM_NODE_TYPE(prismParametersNode));
4521+ // }
4522+ // }
4523+
45014524 // Modify send node's endLoc to be position before first space
45024525 // This fixes location for cases like:
45034526 // Module.new do
@@ -4526,8 +4549,9 @@ unique_ptr<parser::Node> Translator::translateCallWithBlock(pm_node_t *prismBloc
45264549// - `rescue`: a list of `Resbody` nodes, each representing a `rescue` clause.
45274550// - `else_`: an optional node representing the `else` clause.
45284551//
4529- // This function and the PM_BEGIN_NODE case translate between the two representations by processing the `pm_rescue_node`
4530- // (and its linked `subsequent` nodes) and assembling the corresponding `Rescue` and `Resbody` nodes in Sorbet's AST.
4552+ // This function and the PM_BEGIN_NODE case translate between the two representations by processing the
4553+ // `pm_rescue_node` (and its linked `subsequent` nodes) and assembling the corresponding `Rescue` and `Resbody`
4554+ // nodes in Sorbet's AST.
45314555unique_ptr<parser::Node> Translator::translateRescue (pm_begin_node *parentBeginNode) {
45324556 auto *prismRescueNode = parentBeginNode->rescue_clause ;
45334557 ENFORCE (prismRescueNode, " translateRescue() should only be called if there's a `rescue` clause." )
@@ -4702,7 +4726,8 @@ NodeVec Translator::translateEnsure(pm_begin_node *beginNode) {
47024726}
47034727
47044728// Translates the given Prism Statements Node into a `parser::Begin` node or an inlined `parser::Node`.
4705- // @param inlineIfSingle If enabled and there's 1 child node, we skip the `Begin` and just return the one `parser::Node`
4729+ // @param inlineIfSingle If enabled and there's 1 child node, we skip the `Begin` and just return the one
4730+ // `parser::Node`
47064731// @param overrideLocation If provided, use this location for the Begin node instead of the statements node location
47074732unique_ptr<parser::Node> Translator::translateStatements (pm_statements_node *stmtsNode, bool inlineIfSingle,
47084733 core::LocOffsets overrideLocation) {
@@ -4767,7 +4792,8 @@ unique_ptr<parser::Node> Translator::translateIfNode(core::LocOffsets location,
47674792// The only exception is that dynamic constant path *operator* assignments inside of a method definition
47684793// do not raise a SyntaxError at runtime, so we want to skip the workaround in that case.
47694794// However, within this method, both regular constant path assignments and constant path operator assignments
4770- // are passed in as `pm_constant_path_node` types, so we need an extra boolean flag to know when to skip the workaround.
4795+ // are passed in as `pm_constant_path_node` types, so we need an extra boolean flag to know when to skip the
4796+ // workaround.
47714797//
47724798// Usually returns the `SorbetLHSNode`, but for constant writes and targets,
47734799// it can can return an `LVarLhs` as a workaround in the case of a dynamic constant assignment.
@@ -4808,7 +4834,8 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
48084834 if constexpr (isConstantPath) { // Handle constant paths, has a parent node that needs translation.
48094835 if (auto *prismParentNode = node->parent ) {
48104836 // This constant reference is chained onto another constant reference.
4811- // E.g. given `A::B::C`, if `node` is pointing to the root, `A::B` is the `parent`, and `C` is the `name`.
4837+ // E.g. given `A::B::C`, if `node` is pointing to the root, `A::B` is the `parent`, and `C` is the
4838+ // `name`.
48124839 // A::B::C
48134840 // / \
48144841 // A::B ::C
@@ -5031,7 +5058,8 @@ unique_ptr<parser::Mlhs> Translator::translateMultiTargetLhs(PrismNode *node, co
50315058// Extracts the desugared expressions out of a "scope" (class/sclass/module) body.
50325059// The body can be a Begin node comprising multiple statements, or a single statement.
50335060// Return nullopt if the body does not have all of its expressions desugared.
5034- // TODO: make the return non-optional after direct desugaring is complete. https://github.com/Shopify/sorbet/issues/671
5061+ // TODO: make the return non-optional after direct desugaring is complete.
5062+ // https://github.com/Shopify/sorbet/issues/671
50355063optional<ast::ClassDef::RHS_store> Translator::desugarScopeBodyToRHSStore (pm_node *prismBodyNode,
50365064 unique_ptr<parser::Node> &scopeBody) {
50375065 ENFORCE (directlyDesugar, " desugarScopeBodyToRHSStore should only be called when direct desugaring is enabled" );
0 commit comments