From 422eda09f15e09b6fc2777f93c390e379273b0f9 Mon Sep 17 00:00:00 2001 From: Aditya Pillai Date: Wed, 18 Oct 2023 13:30:16 -0700 Subject: [PATCH] allow both importing static and strict Summary: In the next commit, we separate strict analysis from static compilation. Since this is the case, some users may expect static compilation to also perform strict analysis (in the case where someone just calls `import __static__` without `from __strict__ import allow_side_effects`). This commit provides a forwards-compatible way to make this codemod before both strict analysis is decoupled. Reviewed By: DinoV Differential Revision: D49736501 fbshipit-source-id: ef7fc1029829ff0a91a39263fc948957671f4373 --- .../Compiler/abstract_module_loader.cpp | 9 +++---- .../comparison_tests/interpreter_test.txt | 27 ------------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/StrictModules/Compiler/abstract_module_loader.cpp b/StrictModules/Compiler/abstract_module_loader.cpp index 00f13920de0..3340f41a1ea 100644 --- a/StrictModules/Compiler/abstract_module_loader.cpp +++ b/StrictModules/Compiler/abstract_module_loader.cpp @@ -113,12 +113,11 @@ std::pair getModuleKindFromStmts( if (modKind == std::nullopt) { modKind = tempModKind; goto loop_continue; + } else if (modKind == ModuleKind::kStrict) { + modKind = tempModKind; + goto loop_continue; } else { - modInfo->setFlagError( - stmt->lineno, - stmt->col_offset, - "strict flag must be at top of module"); - return {ModuleKind::kNonStrict, should_analyze}; + goto loop_continue; } } } diff --git a/StrictModules/Tests/comparison_tests/interpreter_test.txt b/StrictModules/Tests/comparison_tests/interpreter_test.txt index adcdfcf4406..8bc3e613645 100644 --- a/StrictModules/Tests/comparison_tests/interpreter_test.txt +++ b/StrictModules/Tests/comparison_tests/interpreter_test.txt @@ -9826,33 +9826,6 @@ x = 1 x --- --- -test_flag_after_two_doc ---- -'''First docstring.''' -'''Second "docstring."''' -import __strict__ -x = 1 ---- ---- -3 0 BadStrictFlagException strict flag must be at top of module ---- -test_flag_after_import ---- -import foo -import __strict__ ---- ---- -2 0 BadStrictFlagException strict flag must be at top of module ---- -test_duplicate_flag ---- -import __strict__ -import foo -import __strict__ ---- ---- -3 0 BadStrictFlagException strict flag must be at top of module ---- test_flag_with_imports --- import __strict__, foo