diff --git a/Analysis/src/Frontend.cpp b/Analysis/src/Frontend.cpp index 710e3699..125f2457 100644 --- a/Analysis/src/Frontend.cpp +++ b/Analysis/src/Frontend.cpp @@ -38,6 +38,7 @@ LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverToJson, false) LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false) LUAU_FASTFLAGVARIABLE(LuauTypecheckLimitControls, false) LUAU_FASTFLAGVARIABLE(CorrectEarlyReturnInMarkDirty, false) +LUAU_FASTFLAGVARIABLE(LuauDefinitionFileSetModuleName, false) namespace Luau { @@ -165,6 +166,11 @@ LoadDefinitionFileResult Frontend::loadDefinitionFile(GlobalTypes& globals, Scop LUAU_TIMETRACE_SCOPE("loadDefinitionFile", "Frontend"); Luau::SourceModule sourceModule; + if (FFlag::LuauDefinitionFileSetModuleName) + { + sourceModule.name = packageName; + sourceModule.humanReadableName = packageName; + } Luau::ParseResult parseResult = parseSourceForModule(source, sourceModule, captureComments); if (parseResult.errors.size() > 0) return LoadDefinitionFileResult{false, parseResult, sourceModule, nullptr}; diff --git a/tests/TypeInfer.definitions.test.cpp b/tests/TypeInfer.definitions.test.cpp index 86f619fd..30153280 100644 --- a/tests/TypeInfer.definitions.test.cpp +++ b/tests/TypeInfer.definitions.test.cpp @@ -441,4 +441,27 @@ TEST_CASE_FIXTURE(Fixture, "class_definitions_reference_other_classes") REQUIRE(result.success); } +TEST_CASE_FIXTURE(Fixture, "definition_file_has_source_module_name_set") +{ + ScopedFastFlag sff{"LuauDefinitionFileSetModuleName", true}; + + LoadDefinitionFileResult result = loadDefinition(R"( + declare class Foo + end + )"); + + REQUIRE(result.success); + + CHECK_EQ(result.sourceModule.name, "@test"); + CHECK_EQ(result.sourceModule.humanReadableName, "@test"); + + std::optional fooTy = frontend.globals.globalScope->lookupType("Foo"); + REQUIRE(fooTy); + + const ClassType* ctv = get(fooTy->type); + + REQUIRE(ctv); + CHECK_EQ(ctv->definitionModuleName, "@test"); +} + TEST_SUITE_END();