Repository: godotengine/godot (language: cpp)

Issue:
Exported vars  without a default set, of enum types with no entry with a value of 0, show misleading info in inspector
### Godot version

v4.0.rc6.official [0cd148313]

### System information

Arch Linux

### Issue description

In GDScript, when exporting a variable of an enum type that does NOT have an entry with value `0` (zero), and you don't  a default value, the inspector looks as if you have selected the first element, but in truth, the value of the variable is `0`.

Given the following snippet:

```
enum Foo{
	bar = 1,
	foobar = 2,
}
@export var foo : Foo
```

The inspector looks like this:

![image](https://user-images.githubusercontent.com/7486114/221964166-7493668b-bf60-4f7a-b95f-787081599882.png)

This suggests `bar` is selected, and thus `foo` should be `1`.

However,
```
func _ready():
	print(str(foo))
```
prints `0` (zero).

If you _do_ give a default:

```
@export var foo : Foo = Foo.bar
```

the inspector looks exactly the same as it did without the default specified, but the output _is_ the (expected) `1`. As a user, I thus can't tell the difference without inspecting the code. 

As a user, I expect that whatever is shown in the inspector is a representation of what I'll get when I run the code. So when no default is specified, I expect that either (the inspector shows `0` or `null`) _or_ (the value of `foo` ends up being `bar` instead of `0`). Ideally, I would like it to do the latter, but I think that the former is technically more correct

### Steps to reproduce

1. Make a new scene 
2. Attach the following script:
```
extends Node

enum Foo{
	bar = 1,
	foobar = 2,
}

@export var foo : Foo

func _ready():
	print(str(foo))
```
3. Observe that the inspector for this node suggest that `foo`  is set to `bar`.
4. Run the code, and observe the ouput prints `0` instead.
5. Change the export line to `@export var foo : Foo = Foo.bar`
6. Observe that the outliner looks exactly the same as before
7. Run the code, and observe that the output now reads `1`.

### Minimal reproduction project

n/a, but can be supplied if helpful. 


Discussion / hints:
Also valid with C# exported variables as seen in #76933.
See also #75555. The inspector should take into account that the property may have the wrong type or value and display it. For example, if the number is out of range, the text should be red and/or an exclamation mark icon should be displayed. In the case of enums, `OptionButton` has support for the unselected state.
This is still the case in 4.2.1. 

A small warning to use a default value with `enums` will be helpful if it's hard to change the editor's behavior. I lost a few hair patches figuring this out!
I opened #90756 to show a warning if the default value isn't set (when `0` isn't a valid value). Ideally, the default would be the first value of the enum, but that's a bit difficult to figure out.

Still, the inspector should show the actual value and perhaps warn when it's not part of the enum.

Fix patch:
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index 9ea0c2de9a75..52780d7c5889 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -321,6 +321,9 @@ void EditorPropertyTextEnum::update_property() {
 		}
 	} else {
 		option_button->select(default_option);
+		if (default_option < 0) {
+			option_button->set_text(current_value);
+		}
 	}
 }
 
@@ -699,6 +702,7 @@ void EditorPropertyEnum::update_property() {
 	Variant current = get_edited_property_value();
 	if (current.get_type() == Variant::NIL) {
 		options->select(-1);
+		options->set_text("<null>");
 		return;
 	}
 
@@ -709,6 +713,8 @@ void EditorPropertyEnum::update_property() {
 			return;
 		}
 	}
+	options->select(-1);
+	options->set_text(itos(which));
 }
 
 void EditorPropertyEnum::setup(const Vector<String> &p_options) {


Test patch: