@@ -1886,6 +1886,7 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
18861886 // It's important that in all branches `enterNameUTF8` is called, which `translateConstantName` does,
18871887 // so that the name is available for the rest of the pipeline.
18881888 auto name = translateConstantName (node->name );
1889+ auto sorbetName = gs.enterNameConstant (name);
18891890
18901891 if (isInMethodDef && replaceWithDynamicConstAssign) {
18911892 // Check if this is a dynamic constant assignment (SyntaxError at runtime)
@@ -1899,6 +1900,8 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
18991900 is_same_v<PrismLhsNode, pm_constant_path_node>;
19001901
19011902 std::unique_ptr<parser::Node> parent;
1903+ ast::ExpressionPtr parentExpr;
1904+
19021905 if constexpr (isConstantPath) { // Handle constant paths, has a parent node that needs translation.
19031906 if (auto prismParentNode = node->parent ; prismParentNode != nullptr ) {
19041907 // This constant reference is chained onto another constant reference.
@@ -1909,9 +1912,12 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
19091912 // / \
19101913 // A ::B
19111914 parent = translate (prismParentNode);
1915+ parentExpr = parent ? parent->getCachedDesugaredExpr () : nullptr ;
19121916 } else { // This is the root of a fully qualified constant reference, like `::A`.
19131917 auto delimiterLoc = translateLoc (node->delimiter_loc ); // The location of the `::`
1918+
19141919 parent = make_node<parser::Cbase>(delimiterLoc);
1920+ parentExpr = MK::Constant (delimiterLoc, core::Symbols::root ());
19151921 }
19161922 } else { // Handle plain constants like `A`, that aren't part of a constant path.
19171923 static_assert (
@@ -1928,9 +1934,16 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
19281934 location = translateLoc (node->name_loc );
19291935 }
19301936 parent = nullptr ;
1937+ parentExpr = MK::EmptyTree ();
1938+ }
1939+
1940+ auto sorbetNode = make_node<SorbetLHSNode>(location, move (parent), sorbetName);
1941+
1942+ if (parentExpr != nullptr ) {
1943+ sorbetNode->cacheDesugaredExpr (MK::UnresolvedConstant (location, move (parentExpr), sorbetName));
19311944 }
19321945
1933- return make_node<SorbetLHSNode>(location, move (parent), gs. enterNameConstant (name)) ;
1946+ return sorbetNode ;
19341947}
19351948
19361949core::NameRef Translator::translateConstantName (pm_constant_id_t constant_id) {
0 commit comments