Repository: luau-lang/luau (2026-07-05T17:56:20Z)

Issue:
`types.singleton()` misleading / incorrect error
<img width="1740" height="401" alt="Image" src="https://github.com/user-attachments/assets/957e04f5-bb99-4e1d-9b10-743e4043b822" />

https://play.luau.org/#N4IgbiBcBMA0IDMqgE4FMAOKD2A6ANgK4CGhUIALgJ4ZoAEx+AlsQM50C8dwAvgDoA7arToJCAgMYUm2AXQC2abAHcAFAEpBdOugqEUc4Wla5WTAQHN8aCrNWMWrTQLQCAJoIC0nugHJFKr50RqLiUjJyaCg46G4MFDri0oqQXj4A2qwUKOYWdHwgAcoFALqQAMyQwTTGprnWtgJVEsQCvgkS6MQU9GaWDbKiOPJ0AAYARtjY1q2j1bSCIT1ZnApKygA8AHyCIDzwrMgg2BjJTABe3REAMmhgaPhQcCAS2PIYTNYoAEpo8sQoADWh0g2UIaB4PCAA


Discussion:

Patch:
diff --git a/Analysis/src/TypeFunctionRuntime.cpp b/Analysis/src/TypeFunctionRuntime.cpp
index f6d0db0a6..df3d1122f 100644
--- a/Analysis/src/TypeFunctionRuntime.cpp
+++ b/Analysis/src/TypeFunctionRuntime.cpp
@@ -31,6 +31,7 @@ LUAU_FASTFLAGVARIABLE(LuauTypeFunctionSerializeArgNames)
 LUAU_FASTFLAGVARIABLE(LuauTypeFunctionRobustness)
 LUAU_FASTFLAGVARIABLE(LuauUdtfTypeIsSubtypeOf)
 LUAU_FASTFLAGVARIABLE(LuauTypeFunctionTableIndexerIsReadOnly)
+LUAU_FASTFLAGVARIABLE(LuauUdtfCreateSingletonFixErrorMessage)
 
 namespace Luau
 {
@@ -532,7 +533,10 @@ static int createSingleton(lua_State* L)
         return 1;
     }
 
-    luaL_error(L, "types.singleton: can't create singleton from `%s` type", lua_typename(L, 1));
+    if (FFlag::LuauUdtfCreateSingletonFixErrorMessage)
+        luaL_error(L, "types.singleton: can't create a singleton from a %s", luaL_typename(L, 1));
+    else
+        luaL_error(L, "types.singleton: can't create singleton from `%s` type", lua_typename(L, 1));
 }
 
 // Luau: `types.generic(name: string, ispack: boolean?) -> type


Test patch:
diff --git a/tests/TypeFunction.user.test.cpp b/tests/TypeFunction.user.test.cpp
index f383a104a..3a5bfc17a 100644
--- a/tests/TypeFunction.user.test.cpp
+++ b/tests/TypeFunction.user.test.cpp
@@ -20,6 +20,7 @@ LUAU_FASTFLAG(LuauUdtfTypeIsSubtypeOf)
 LUAU_FASTFLAG(LuauTypeFunctionTableIndexerIsReadOnly)
 LUAU_FASTFLAG(LuauReadOnlyIndexers)
 LUAU_DYNAMIC_FASTINT(LuauTypeFunctionSerdeIterationLimit)
+LUAU_FASTFLAG(LuauUdtfCreateSingletonFixErrorMessage)
 
 TEST_SUITE_BEGIN("UserDefinedTypeFunctionTests");
 
@@ -3438,4 +3439,25 @@ TEST_CASE_FIXTURE(BuiltinsFixture, "issubtypeof_table_indexer")
     CHECK(toString(requireType("c")) == "true");
 }
 
+TEST_CASE_FIXTURE(BuiltinsFixture, "types_singleton_error_message")
+{
+    DOES_NOT_PASS_OLD_SOLVER_GUARD();
+    ScopedFastFlag fixErrorMessage{FFlag::LuauUdtfCreateSingletonFixErrorMessage, true};
+
+    CheckResult results = check(R"(
+        type alias = {}
+        type function meow()
+            return types.singleton(alias :: any)
+        end
+
+        type test = meow<>
+    )");
+
+    LUAU_REQUIRE_ERROR_COUNT(1, results);
+    CHECK_EQ(
+        toString(results.errors[0]),
+        "'meow' type function errored at runtime: [string \"meow\"]:4: types.singleton: can't create a singleton from a type"
+    );
+}
+
 TEST_SUITE_END();