Repository: godot
Issue: Errors creating dynamic scripts containing statically typed class_name variables
Labels: bug,discussion,topic:gdscript

### Tested versions

 v4.2.stable.official.46dc27791

### System information

Godot v4.2.stable - macOS 13.4.1 - Vulkan (Forward+) - integrated Apple M1 Pro - Apple M1 Pro (10 Threads)

### Issue description

Creating a `GDScript` object causes `ERROR: Parameter "p_script->implicit_initializer" is null.` in some specific cases.  If the script extends a script that contains a statically typed variable who's type is a `class_name` in another script and the `resource_path` is empty then the error can appear.

The fix is probably to not create `GDScript` objects with an empty `resource_path` as this seems to fix it.  It _seems_ to be so finicky I figured it should be reported as it might pop up in other edge cases.  Also, what else was I going to do with all this sample code I had generated? 

If there are any tips on populating `resource_path` other than `str('arbitrary_text_', counter)` I'd love to hear them.

# Basic Setup
`res://src/foo.gd`
``` gdscript
class_name Foo
var bar = 'bar'
```
`res://src/node_uses_foo.gd`
```gdscript
extends Node
var f := Foo.new()
```

Creating a dynamic script that extends `node_uses_foo.gd` generates the error
```gdscript
extends SceneTree

func _init():
	var DynamicScript = GDScript.new()
	DynamicScript.source_code = "extends 'res://src/node_uses_foo.gd'"
	DynamicScript.resource_path = ''
	DynamicScript.reload()

	var inst = DynamicScript.new() # ERROR: Parameter "p_script->implicit_initializer" is null.
	print(inst) # a node
	print(inst.f) # null

	quit()
```

# Additional Info
* This was discovered in [this GUT issue](https://github.com/bitwes/Gut/issues/570)
* I'm pretty sure this is the cause of [this other GUT issue](https://github.com/bitwes/Gut/issues/490#issuecomment-1557970317) which documents some other odd behavior.
* If `f` in `node_uses_foo.gd` is not statically typed then things break less (I think, I've gotten lost in all the paths you can take to fix/replicate the issue).
* Making a reference to `Foo` before creating the dynamic `GDScript` object can prevent the error in some cases.
* Making the `resource_path` unique for each `GDScript` object prevents the error.
* Using/not using the `GDScript` object can affect whether or not the error occurs.


### Steps to reproduce

The MRP project has various `SceneTree` scripts in `src` that illustrate the nuances of the error.  Some make use of a static class defined in [`src/dynamic.gd`](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/dynamic.gd)

* [error_case_1.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/error_case_1.gd) _This one is the most convoluted of the bunch but has some good info in it._
* [error_case_2.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/error_case_2.gd)
* [error_case_3.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/error_case_3.gd)
* [error_case_4.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/error_case_4.gd)
* [ok_case_1.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/ok_case_1.gd)
* [ok_case_2.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/ok_case_2.gd)
* [ok_case_3.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/ok_case_3.gd)
* [ok_case_4.gd](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/src/ok_case_4.gd)

There is also a [GUT](https://github.com/bitwes/Gut) unit test where I was first able to reliably replicate the issue (the GUT addon is not included in the project so you must install it from the Asset Library)
* [test_illustrate_issue](https://github.com/bitwes/GodotImplicitInitializerIssue/blob/main/test/test_illustrate_issue.gd)

### Minimal reproduction project (MRP)

Run the various `src/error_case_*` and `src/ok_case_*` `SceneTree` scripts.  There is also a [GUT](https://github.com/bitwes/Gut) unit test at `test/test_illustrate_issue.gd` that illustrates how the issue was originally found.  This requires you install GUT into the project.  Run the test with `godot -s addons/gut/gut_cmdln.gd`.

https://github.com/bitwes/GodotImplicitInitializerIssue