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
GDScript: Fix some issues with assignments that involve untyped things #70733
Conversation
89626a4
to
5c868fd
Compare
Rebased to resolve conflicts with #62688. Fixed its regression: func test():
var foo: bool = true
foo += 'bar' # this should be invalid |
I agree with (3), (4). |
About (2). This currently works - About (1). "is untyped so any assignment is safe" - don't think it is true. It is safe for |
5c868fd
to
1a4f455
Compare
Small change - added same downgrade logic to initializer too: var x = 'weak'
# somewhere after that:
var y: int = x We hope that by the time the assignment will happen |
ba993ad
to
6298f24
Compare
Rebased to resolve small conflict with #71192, which was fixing the issue (one of) already fixed here. |
The only thing about inferred types is that if we allow something like: var untyped = 5
var typed := untyped then we have to be 100% sure that all inferred types are always correct. There has been cases in the past where the analyzer were assigning inferred types that weren't guaranteed to be true. The trivial case I've shown here is obvious but I assume this means any It would naturally be a good thing if inferred types were always correct (and downgraded to |
var untyped = 5
var typed := untyped Currently works, yes. Actually forgot to ask about that at last meeting, was planning to do so tomorrow. |
But for record, this thing |
6298f24
to
38c214d
Compare
Well, it can be done in different PR, but if tests rely on this then such PR would have to change this test as well (or remove them). In this sense, I think it would be better to change the tests here to not rely on this, or remove them altogether (I get it's bad to not have tests, but have some relying on unintended behavior is also bad IMO). |
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.
Apart from my comments the PR is good and could be merged. If anything we sort the tests in another PR.
Thanks! |
As show with
number
variable a single assignment (even of the same type) currently makes a weakly inferred variable a variant.I changed the logic about downgrading of such weakly types:
SubscriptNode
now handled too, not only directIdentifierNode
, so it means that it is possible to downgrade member variables of other classes now and thatself.prop
will not be skipped.The fact that it is possible to downgrade member variables of other classes means that theoretically decision on which type of assignment to use (conversion one or a basic) can be moved from analyzer to compiler in the future.
(Also added one line to set
is_self
to true inreduce_call
if a call happens on a literal self, it is unrelated, can remove.)