From 2469dbae153066fad83edcced82f17aee77d0a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 11 Jul 2022 20:34:44 +0800 Subject: resolve #1029 treat _ENV = {} as local _ENV = {} local _ENV = nil will disable all globals local _ENV = {} will enable all globals local _ENV = {} ---@type mathlib will open globals in mathlib --- test/diagnostics/common.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test/diagnostics') diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 0df678d1..fab02caf 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -132,6 +132,40 @@ print(1) _ENV = nil ]] +TEST [[ +---@diagnostic disable: undefined-global +_ENV = nil +() -- `print` and `A` should warning +]] + +TEST [[ +---@diagnostic disable: undefined-global +local _ENV = nil +() -- `print` and `A` should warning +]] + +TEST [[ +_ENV = {} +print(A) -- no warning +]] + +TEST [[ +local _ENV = {} +print(A) -- no warning +]] + +TEST [[ +---@type iolib +_ENV = {} +(stderr) -- `print` is warning but `stderr` is not +]] + +TEST [[ +---@type iolib +local _ENV = {} +(stderr) -- `print` is warning but `stderr` is not +]] + TEST [[ local _ENV = { print = print } print(1) -- cgit v1.2.3