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

GDScript: empty class definition leads to error somewhere else #56703

Open
just-like-that opened this issue Jan 11, 2022 · 9 comments
Open

GDScript: empty class definition leads to error somewhere else #56703

just-like-that opened this issue Jan 11, 2022 · 9 comments

Comments

@just-like-that
Copy link

just-like-that commented Jan 11, 2022

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

# bug_class_one_liner.gd
extends Node2D

# line 07 leads to
# 'error(16,1): The method "to_local" isn't declared in the current class.'
# (line 08 to 09 works - same code including line-break.)
class WorxNot: pass
#class Worx:
#	pass

var var1

var var2

func icon_at(pos: Vector2):
	pos = to_local(pos)
	# other statements

leads to error at line "pos = to_local(pos)" in function icon_at().

Minimal reproduction project

bug_class_one_liner.zip

@Calinou
Copy link
Member

Calinou commented Jan 11, 2022

I can't reproduce this on master b6b81e8, so this is fixed in the new GDScript implementation. I can reproduce this on 3.x cd47ff1 though.

image

@Calinou Calinou added this to the 3.5 milestone Jan 11, 2022
@arlez80
Copy link
Contributor

arlez80 commented Jun 8, 2022

I also found this bug at Godot 3.4.3 and 3.4.4.
It will be define all functions/members under empty class.

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( ) )

@kdiduk
Copy link
Contributor

kdiduk commented Jun 10, 2022

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.

@Calinou
Copy link
Member

Calinou commented Jun 10, 2022

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 🙂

@kdiduk
Copy link
Contributor

kdiduk commented Jun 12, 2022

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 pass on the same line after the colon, but then the documentation for GDScript grammar should be updated (for 4.0 as well 🙂).

kdiduk added a commit to kdiduk/godot that referenced this issue Jun 21, 2022
…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
@kdiduk
Copy link
Contributor

kdiduk commented Jun 28, 2022

The fix for this issue is ready here #61993, waiting to be merged 🙂

@akien-mga akien-mga modified the milestones: 3.5, 3.x Jun 28, 2022
@just-like-that
Copy link
Author

just-like-that commented Jun 29, 2022 via email

@akien-mga akien-mga modified the milestones: 3.x, 3.6 Aug 30, 2022
@akien-mga
Copy link
Member

Fixed by #61993.

Riordan-DC pushed a commit to Riordan-DC/godot that referenced this issue Jan 24, 2023
…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
@akien-mga
Copy link
Member

Reopening as #61993 was reverted due to regressions.

@akien-mga akien-mga reopened this Jul 17, 2024
@akien-mga akien-mga modified the milestones: 3.6, 3.x Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants