Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@deprecated is ignored on globals when assigned by another global #3074

Open
rhys-vdw opened this issue Feb 13, 2025 · 2 comments
Open

@deprecated is ignored on globals when assigned by another global #3074

rhys-vdw opened this issue Feb 13, 2025 · 2 comments

Comments

@rhys-vdw
Copy link

rhys-vdw commented Feb 13, 2025

meta.lua

---@meta

--
--Assigning a global fails.
--

Global = {}

---@deprecated
AssignedGlobal = Global


--
--Assigning a field of a global also fails.
--

Global.field = {}

---@deprecated
AssignedGlobalField = Global.field

--
--Standard object works.
--

---@deprecated
Object = {}


--
--Assignment of local object works.
--

local alsoWorking = {}

---@deprecated
AssignedLocalObject = alsoWorking

test.lua

local x = AssignedGlobal
local y = AssignedGlobalField
local z = Object
local a = AssignedLocalObject

Image

Interestingly the deprecation is shown correctly in the autocomplete:

Image

@rhys-vdw rhys-vdw changed the title Allow @deprecated to be applied to globals (and classes) @deprecated is ignored on globals when assigned by another global Feb 13, 2025
@tomlau10
Copy link
Contributor

From maintainer's comment of another issue: #2784 (comment)

This is a dilemma. The current strategy is that when an object has multiple definitions, as long as one of the definitions is not marked as deprecated, the entire object is not considered deprecated.
This is to allow users to re-implement built-in functions that have been deprecated, such as table.getlen.

(translated by chatgpt)


When assigning a global to another global, there exists two definition for that variable:

  • one is with @deprecated
  • another one is not
  • => thus it does not fulfill the all definition are marked as deprecated condition

While when assigning a local to global, seems that it is not considered as a definition of that global.
You can verify this by doing a goto definition on your x/y/z/a variables:

  • x & y have 2 definitions
  • z & a have only 1 definition

IIUC, this is by design: as long as one of the definitions is not marked as deprecated, the entire object is not considered deprecated.

In addition, from wiki the @deprecated only officially supports functions but not variables / fields.
https://luals.github.io/wiki/annotations/#deprecated
Using @deprecated to mark fields may result in undefined behavior, as discussed here: #1313 (comment)

@rhys-vdw
Copy link
Author

rhys-vdw commented Feb 14, 2025

Thanks for the explanation. I'd need to look into it more to decide whether this behavior is sensible. In my case I was able to work around it this way:

---@class Foo
local foo = {}

---@deprecated
GlobalFoo = nil ---@type Foo

In addition, from wiki the @deprecated only officially supports functions but not variables / fields.

I noticed this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants