Repository: luau-lang/luau (2026-01-23T21:10:26Z)

Issue:
[Luau.Ast] Signature mismatch for prettyPrint in PrettyPrinter.h vs PrettyPrinter.cpp
**Description**
There is a signature mismatch between the declaration and definition of `Luau::prettyPrint`.

In `Ast/include/Luau/PrettyPrinter.h`, the function is declared as accepting a single argument:
```cpp
std::string prettyPrint(AstStatBlock& ast);
```

However, in `Ast/src/PrettyPrinter.cpp`, the definition requires two arguments:
```cpp
std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap)
{
    // ... implementation
}
```

**Expected behavior**
The header declaration should match the source definition, preferably allowing `cstNodeMap` to be optional via a default argument or function overloading.


Discussion:

Patch:
diff --git a/Ast/include/Luau/PrettyPrinter.h b/Ast/include/Luau/PrettyPrinter.h
index 6a28a47c69..423c61e16f 100644
--- a/Ast/include/Luau/PrettyPrinter.h
+++ b/Ast/include/Luau/PrettyPrinter.h
@@ -23,7 +23,8 @@ std::string toString(AstNode* node);
 void dump(AstNode* node);
 
 // Never fails on a well-formed AST
-std::string prettyPrint(AstStatBlock& ast);
+std::string prettyPrint(AstStatBlock& block);
+std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap);
 std::string prettyPrintWithTypes(AstStatBlock& block);
 std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap);
 
diff --git a/Ast/src/PrettyPrinter.cpp b/Ast/src/PrettyPrinter.cpp
index e65dbb2cd5..2321da3dbe 100644
--- a/Ast/src/PrettyPrinter.cpp
+++ b/Ast/src/PrettyPrinter.cpp
@@ -2064,6 +2064,11 @@ std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap)
     return writer.str();
 }
 
+std::string prettyPrint(AstStatBlock& block)
+{
+    return prettyPrint(block, CstNodeMap{nullptr});
+}
+
 std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap)
 {
     StringWriter writer;


Test patch:
diff --git a/tests/PrettyPrinter.test.cpp b/tests/PrettyPrinter.test.cpp
index 672f1df5b4..65ba6a6c31 100644
--- a/tests/PrettyPrinter.test.cpp
+++ b/tests/PrettyPrinter.test.cpp
@@ -36,6 +36,19 @@ end
     CHECK_EQ(example, prettyPrint(example).code);
 }
 
+TEST_CASE("prettyPrint_AstStatBlock_overload")
+{
+    const std::string code = "local a = 1";
+    ParseOptions options;
+    Allocator allocator;
+    AstNameTable names(allocator);
+    ParseResult result = Parser::parse(code.c_str(), code.size(), names, allocator, options);
+    REQUIRE(result.root != nullptr);
+    
+    std::string printed = prettyPrint(*result.root);
+    CHECK_EQ("local a = 1", printed);
+}
+
 TEST_CASE("string_literals")
 {
     const std::string code = R"( local S='abcdef\n\f\a\020' )";