-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
[3.x] Fix inner class parsing when statement after colon is on the same line (reverted) #61993
[3.x] Fix inner class parsing when statement after colon is on the same line (reverted) #61993
Conversation
If this PR is approved and merged, we need to update documentation for GDScript grammar (both in 3.x and 4.0), because it says that after the colon in the inner class declaration there is a newline: innerClass = "class" IDENTIFIER [ inheritance ] ":" NEWLINE
INDENT [ inheritance NEWLINE ] topLevelDecl { topLevelDecl } DEDENT ; As I understand, the idea is to have it more Python'ic way, where this is allowed: class Foo: pass At least in 4.0 it already works like that. |
For the record, the Please make sure that this doesn't reintroduce the issues that those PRs fixed. |
b77e3ef
to
942b304
Compare
@akien-mga Thank you for mentioning the original PR! Indeed my initial fix re-introduced some issues from them. I've just pushed another implementation. I've implemented a special case for inner classes and it doesn't touch the cases mentioned in those PRs. In this implementation, it's allowed to write like this: class Foo: pass And also, as in Python, it's not allowed to use anything else apart from class Foo: func bar(): pass Some of the test-cases that I've used can be found here: test_inner_classes.gdextends Node2D
class Foo:
func foo():
return "Hello, Foo!"
class Bar extends Foo: pass # inner class
# not allowed: says "unexpected indentation"
# class BadBar: pass
# func bad_bar():
# pass
class FooBar extends Bar:
func foo():
return "Hello, FooBar!"
var foo_var: FooBar = FooBar.new()
class AnotherInnerClass:
func foo(): pass
func _ready(): $RichTextLabel.text = foo_var.foo()
# at the end of file
class BarFoo extends Foo: pass I can also do some refactoring to clean up and eliminate duplicated code. |
942b304
to
f1ce18a
Compare
Looks good to me, my remarks are only about the comment formatting. |
f1ce18a
to
741efb2
Compare
@vnen Thank you for your remarks. I've just pushed new changes with some refactoring. I have eliminated duplicated code blocks, extracting it into separate methods. Could you review it again? |
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.
Looks good to me, just have one style remark.
…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
f830f46
to
5bcc3d4
Compare
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.
Looks good to me
FYI: this pull-request is in the milestone |
Thanks! |
This commit fixes #56703
The fix is to increase indent level when the statement after the colon token is on the same line.
It looks like this issue is a regression introduced after some of the changes. Because in one of the earlier versions of that piece of code the intend level was increased (see this, for example).
Bugsquad edit: