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 STANDALONE_EXPRESSION warning should not apply for preload (due to static initializers) #92022

Closed
RedMser opened this issue May 16, 2024 · 1 comment · Fixed by #92027

Comments

@RedMser
Copy link
Contributor

RedMser commented May 16, 2024

Tested versions

Reproducible in 2ba22d1 (fairly recent master branch build)
Reproducible in v4.3.dev6

System information

Windows 10.0.19044 - dedicated NVIDIA GeForce RTX 2080 (NVIDIA; 31.0.15.5186) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 Threads)

Issue description

A preload expression causes static constructor and variable initializers to run.
However, writing a preload on a standalone line still causes this warning:

Standalone expression (the line has no effect). (STANDALONE_EXPRESSION)

This is already accounted for with load, which does not show a warning in this situation.

Steps to reproduce

In your scene:

extends Node

func _ready() -> void:
	# This has side effects!
	preload("res://static_stuff.gd")

And in static_stuff.gd:

extends Object

static func _static_init() -> void:
	print("side effect 1")

static var static_var = compute()

static func compute():
	print("side effect 2")
	return 5

Despite the STANDALONE_EXPRESSION warning showing, you will see two prints in Output. The warning is not correct here!

Minimal reproduction project (MRP)

preload-standalone-expression.zip

@RedMser
Copy link
Contributor Author

RedMser commented May 16, 2024

FWIW, I don't think a solution would need to involve checking for static initializers, but it would be enough to simply mark preload as a method that can have side-effects.

@RedMser RedMser changed the title GDScript STANDALONE_EXPRESSION when preloading scripts with static initializers GDScript STANDALONE_EXPRESSION warning should not apply for preload (due to static initializers) May 16, 2024
@dalexeev dalexeev added this to the 4.3 milestone May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants