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

Using null as default parameter causes parse error when trying to access members of that parameter #56217

Closed
BeayemX opened this issue Dec 24, 2021 · 2 comments · Fixed by #70464

Comments

@BeayemX
Copy link
Contributor

BeayemX commented Dec 24, 2021

Godot version

v4.0.dev.custom_build [9d02cfa]

System information

Linux Mint - Vulkan API 1.2.131 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1080

Issue description

When having a function that is using a default parameter which is null the parser seemingly always asumes that this variable is null if no further assignment in the function itself happens.
This leads to problems if this variable is a dictionary because members can't be accessed.

The provided code snippets should make it clearer.

Maybe this issue is related? #54643

Steps to reproduce

Not working

func test(data=null):
	if data:
		print(data['test'])  # Accessing this member will cause the ParseError
	else:
		print("no data")

Working

func test(data=null):
	data = data  # This unnecessary line can be used to prevent the ParseError
	if data:
		print(data['test'])  # Now this line is working
	else:
		print("no data")

Minimal reproduction project

No response

@KoBeWi
Copy link
Member

KoBeWi commented Dec 24, 2021

Looks similar to #49183

@akien-mga
Copy link
Member

Confirmed reproducible in 35fff9a.

The error is:

Cannot use subscript operator on a base of type "null".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment