-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Fixed injects into child classes #2841
Conversation
for _, src in ipairs(fields) do | ||
if src.type == "setfield" then | ||
local class = vm.getDefinedClass(uri, source) | ||
if class then | ||
for _, doc in ipairs(class:getSets(uri)) do | ||
if vm.docHasAttr(doc, 'exact') then | ||
return | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The forloop here seems can early break 🤔
local class = vm.getDefinedClass(uri, source)
doesn't depend onsrc
, so it is a constant in this loop- Now whether
class
is nil or not, it is unrelated to outer loop, and checking the whole logic once is enough:- if the class has
exact
attribute => earlyreturn
- if the class is
nil
or has noexact
attribute => earlybreak
- if the class has
for _, src in ipairs(fields) do
if src.type == "setfield" then
local class = vm.getDefinedClass(uri, source)
if class then
for _, doc in ipairs(class:getSets(uri)) do
if vm.docHasAttr(doc, 'exact') then
return
end
end
end
break <-- the break here, because the above logic only need to check once
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, that's true, thanks. I will revisit this code (it's been a few months since I wrote that) and make a follow-up PR for that later.
Thank you! |
Thanks @Luke100000 |
#2573
This change handles "cannot be injected" correctly if the field member is inherited.