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

Can't access keyword identifiers on a Dictionary #61981

Closed
KoBeWi opened this issue Jun 13, 2022 · 4 comments · Fixed by #62830
Closed

Can't access keyword identifiers on a Dictionary #61981

KoBeWi opened this issue Jun 13, 2022 · 4 comments · Fixed by #62830

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Jun 13, 2022

Godot version

803d25a

System information

Windows 10 x64

Issue description

Doing e.g.

var dict = {}
dict.class = "Node"

results in Expected identifier after "." for attribute access. and Expected end of statement after expression, found "class" instead., spammed tens of times. The identifier is incorrectly recognized as a keyword.

Works correctly in 3.x

Steps to reproduce

  1. Use code above

Minimal reproduction project

No response

@ajreckof
Copy link
Member

ajreckof commented Jul 8, 2022

Just stumbled upon this too. To add a bit of information it happens with all reserved keywords (tested with a dozens of the randomly) except for built-in type name.
Capture d’écran 2022-07-08 à 03 07 56

So the bug seems to be linked to the list given here in the doc

@ajreckof
Copy link
Member

ajreckof commented Jul 8, 2022

I followed the link given in the docs that i gave just before and it seems there is no difference marked between keywords and other tokens (such as punctuation, parentheses, etc). I dug a bit more but i'm not acustomed to the source code of Godot. I found that the function parsing is advance in gdscript_parser.cpp. It calls the scan function from gdscript_tokenizer.cpp which will automatically consider the reserved keywords as specific tokens.
The solution might be in the function advance to add a test before scanning to verify if the previous token is not a period and if it is to call a function that would first verify it can be tokenized as an identifier and if it is tokenize it accordingly. If it can't be tokenized as an identifier we can tokenize as normal because we just wan't it to tokenize normally and raise the exception as it is already the case.
As i just realised there is no problem with the $ syntax which means that something similar as already been implemented and can be reused effectively as both cases are quite similar

Edit : based on my last remark i went digging on how it was done with $. I think i found how to fix it but as i have never contributed i will try to make the modification but it might take some time before i get how to do the PR stuff properly

@L4Vo5
Copy link
Contributor

L4Vo5 commented Oct 2, 2022

This is troublesome as Object.get_signal_connection_list() returns a dictionary array where one of the keys is "signal", which triggers this error.

@KoBeWi
Copy link
Member Author

KoBeWi commented Oct 2, 2022

You can use connection["signal"]

@Chaosus Chaosus changed the title Can't access some identifiers on a Dictionary Can't access keyword identifiers on a Dictionary Nov 24, 2022
@akien-mga akien-mga modified the milestones: 4.0, 4.1 Feb 13, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in 4.x Priority Issues Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants