-
-
Notifications
You must be signed in to change notification settings - Fork 20.9k
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: empty class definition leads to error somewhere else #56703
Comments
I also found this bug at Godot 3.4.3 and 3.4.4. one_line.gd extends Node
class TestClass: pass
# These are define under TestClass
var a:int = 42
var b:int = 0
func test( ):
print( "It's works" )
return 1024 test.gd extends Node
func _ready( ):
var one_line = preload("one_line.gd")
# These are error.
# var one_line_inst = one_line.new( )
# print( one_line_inst.a )
# print( one_line_inst.b )
# print( one_line_inst.test( ) )
# These are ok.
var test_class = one_line.TestClass.new( )
print( test_class.a )
print( test_class.b )
print( test_class.test( ) ) |
If no one has started working on it yet, I can make a fix for this bug and submit a PR. Looks like the fix for this should be simple. |
Feel free to open a pull request for this 🙂 |
GDScript grammar specification says that after the colon in the inner class declaration there should be a newline: innerClass = "class" IDENTIFIER [ inheritance ] ":" NEWLINE
INDENT [ inheritance NEWLINE ] topLevelDecl { topLevelDecl } DEDENT ; I can make a fix according to this spec. On the other hand, I can make a fix so that it would allow a statement like |
…e line Implement a special case for allowing "pass" keyword in one-liner class declaration, to be consistent with Python style. ``` class TestClass: pass ``` This commit fixes godotengine#56703
The fix for this issue is ready here #61993, waiting to be merged 🙂 |
Thank you very much.
Looking forward 😃
…On Jun 28, 2022, 10:39, at 10:39, Kirill Diduk ***@***.***> wrote:
The fix for this issue is ready here #61993, waiting to be merged
:slightly_smiling_face:
--
Reply to this email directly or view it on GitHub:
#56703 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
Fixed by #61993. |
…e line Implement a special case for allowing "pass" keyword in one-liner class declaration, to be consistent with Python style. ``` class TestClass: pass ``` This commit fixes godotengine#56703
Reopening as #61993 was reverted due to regressions. |
Godot version
3.4.2
System information
Windows 10
Issue description
Implementing a script class including an inner class with "pass" as body in one line leads to error some place else.
I created the inner class with a given name as a temporary placeholder - prior to full implementation - to use it as an argument in other functions.
The error message itself is just misleading as it refers to a place in code which has nothing to do with the error itself.
I know this is a minor thing. It cost me a bit to figure out what the real cause was.
Steps to reproduce
Inner class definition in single line including pass as body.
class Whatever: pass
leads to error at line "pos = to_local(pos)" in function icon_at().
Minimal reproduction project
bug_class_one_liner.zip
The text was updated successfully, but these errors were encountered: