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

Nested property type lost when accessed from reference #1613

Open
lunarwtr opened this issue Oct 6, 2022 · 8 comments
Open

Nested property type lost when accessed from reference #1613

lunarwtr opened this issue Oct 6, 2022 · 8 comments
Labels
as designed Functioning as intended, will not be modified

Comments

@lunarwtr
Copy link

lunarwtr commented Oct 6, 2022

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

	local A = {}

	---@class B
	---@overload fun(): B
	local B = {}

	---@class C
	---@overload fun(): C
	local C = {}

	A.property1 = B()

	A.property1.property2 = C()

	local refToB = A.property1

	local refToC = refToB.property2

while the local refToB is correctly of type B, it no longer is aware of property2.

image

expected behavior would be that it is aware of the properties assigned to the instance.

Actual Behaviour

presence of property is lost in the "instance" of object B (not definition).

Reproduction steps

  1. Go to '...'
  2. Click '...'
  3. See error '...'

Additional Notes

No response

Log File

No response

@carsakiller
Copy link
Collaborator

Related: #1561

@carsakiller carsakiller added the bug Something isn't working label Oct 6, 2022
@sumneko sumneko added this to the 3.6.0 milestone Oct 9, 2022
@sumneko sumneko added as designed Functioning as intended, will not be modified and removed bug Something isn't working labels Oct 11, 2022
@sumneko
Copy link
Collaborator

sumneko commented Oct 11, 2022

You can not inject fields in this way, use the follow way instead.

---@class B
local B = {}

B.property2 = C()

@sumneko sumneko removed this from the 3.6.0 milestone Oct 11, 2022
@lunarwtr
Copy link
Author

that was just the example, but this sort of behavior manifests itself when you use a reference to a property regardess of how injected field is done.

A.property1.property2 <--- correctly knows property or type...

Here is another example.

test(A.property1)

function test( ref )
ref.property2 <-- unknown
end

@lunarwtr
Copy link
Author

this happens for me when I have a deeply nested property, then want to use a reference to make code smaller / clean vs always using the full. please consider taking closer look.

@sumneko
Copy link
Collaborator

sumneko commented Oct 12, 2022

You can change your code to

local A = {}

---@class B
---@overload fun(): B
local B = {}

---@class C
---@overload fun(): C
local C = {}

---@class B --> add this annotation
A.property1 = B()

A.property1.property2 = C()

local refToB = A.property1

local refToC = refToB.property2

@carsakiller
Copy link
Collaborator

@lunarwtr has your issue been resolved?

@lunarwtr
Copy link
Author

Kind of.. I can apply type annotations in every function, but that is not ideal. None the less I appreciate your work on this.

Here is real example..

In constructor define something.. typing looks perfect.

image

Then in all other functions type is lost. I can do as sumneko suggests and reassign the unknown to a variable with typing.

image

@Mailaender
Copy link

The type is also lost when inside a table. OpenRA/vscode-openra-lua#10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Functioning as intended, will not be modified
Projects
None yet
Development

No branches or pull requests

4 participants