From 8d8c7974f591d30c4859092eb2e034b80d7affd8 Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Thu, 11 May 2023 12:35:56 +0100 Subject: [PATCH] Use correct globalScope in on demand type checker (#923) Fixes #922 Unsure if this needs to be put behind another FFlag, since the on demand type checker fflag currently exists --- Analysis/src/Frontend.cpp | 5 ++++- tests/Autocomplete.test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Analysis/src/Frontend.cpp b/Analysis/src/Frontend.cpp index b6b315c..b16eda8 100644 --- a/Analysis/src/Frontend.cpp +++ b/Analysis/src/Frontend.cpp @@ -38,6 +38,7 @@ LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverToJson, false) LUAU_FASTFLAG(LuauRequirePathTrueModuleName) LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false) LUAU_FASTFLAGVARIABLE(LuauSplitFrontendProcessing, false) +LUAU_FASTFLAGVARIABLE(LuauTypeCheckerUseCorrectScope, false) namespace Luau { @@ -1397,7 +1398,9 @@ ModulePtr Frontend::check(const SourceModule& sourceModule, Mode mode, std::vect } else { - TypeChecker typeChecker(globals.globalScope, forAutocomplete ? &moduleResolverForAutocomplete : &moduleResolver, builtinTypes, &iceHandler); + TypeChecker typeChecker(FFlag::LuauTypeCheckerUseCorrectScope ? (forAutocomplete ? globalsForAutocomplete.globalScope : globals.globalScope) + : globals.globalScope, + forAutocomplete ? &moduleResolverForAutocomplete : &moduleResolver, builtinTypes, &iceHandler); if (prepareModuleScope) { diff --git a/tests/Autocomplete.test.cpp b/tests/Autocomplete.test.cpp index 3dc75d6..cf92843 100644 --- a/tests/Autocomplete.test.cpp +++ b/tests/Autocomplete.test.cpp @@ -3503,4 +3503,26 @@ local a: T@1 CHECK_EQ(ac.context, AutocompleteContext::Type); } +TEST_CASE_FIXTURE(ACFixture, "frontend_use_correct_global_scope") +{ + ScopedFastFlag sff("LuauTypeCheckerUseCorrectScope", true); + + loadDefinition(R"( + declare class Instance + Name: string + end + )"); + + CheckResult result = check(R"( + local a: unknown = nil + if typeof(a) == "Instance" then + local b = a.@1 + end + )"); + auto ac = autocomplete('1'); + + CHECK_EQ(1, ac.entryMap.size()); + CHECK(ac.entryMap.count("Name")); +} + TEST_SUITE_END();