Repository: godot
Issue: Some built-in methods like get_path passed as string format argument bypass unsupported format character detection, and previous resolved formatted string will be reused
Labels: bug,topic:core

### Godot version

v4.0.2.stable.official [7a0977ce2]

### System information

Linux Ubuntu 22.04 with Unity desktop

### Issue description

Usually, the code parser detects bad format characters like this:

```gd
print("%a" % 0)
```

and shows an edit-time error:

> "unsupported format character in operator %"

but when using some built-in methods such as `get_path`, or arrays:

```gd
print("%a" % get_path())
print("%a" % [0])
```

the error is not detected and you can run the code. This is the 1st part of this issue.

Then, when running the code, since the formatting is bad, you get UB. So I don't know if it's worth mentioning the result since fixing the 1st part should prevent the 2nd part from happening, but here we go:

When the line with the faulty format is run, you get an error:

> E 0:00:00:0416   assert.gd:25 @ _ready(): unsupported format character
  <C++ Error>    Condition "!valid" is true.
  <C++ Source>   core/variant/variant_op.h:1002 @ validated_evaluate()
  <Stack Trace>  assert.gd:25 @ _ready()

but the line is still executed, except it replaces the content of the formatted string with the previous valid formatted string passed to the same function (here, `print`). If there was no previous call to that function with a formatted string (at least not immediately in the same block of code), then the string is considered empty.

List of tested functions:
- print
- push_warning
- push_error
- assert (when condition is false on the line with the bad format)

List of built-in functions that bypass format character parsing:
- get_path
- get_angle_to(Vector2)
and probably others?

### Steps to reproduce

1. Open demo.tscn
2. Open bad_format.gd and check that _ready currently uncomments the block with print only
3. Run the scene, it will execute bad_format.gd _ready
4. Observe the output: the print message "1. should appear only once in output" appears twice
5. Repeat, commenting out a block and uncommenting the next one each time, to test one by one the other functions: psuh_warning, push_error, assert
6. Bonus: you can try other methods or simple expressions to see that the bug does not occur. Or you can remove the first line with valid format for each function, so you see the case with empty string (not much to see, except the assert that will show the same thing as if no assertion string or an empty assertion string was given, i.e. just "Assertion failed."

### Minimal reproduction project

[v4.0.2 - Invalid string format in assert will cause previous assert message to be used.zip](https://github.com/godotengine/godot/files/11374985/v4.0.2.-.Invalid.string.format.in.assert.will.cause.previous.assert.message.to.be.used.zip)

For quick testing in any project, you can also copy-paste this in any script attached on a node:

```gd
func _ready():
	print("1. should appear only once in output" % [])
	print("%a" % [0])

	push_warning("2. should appear only once in warnings" % [])
	push_warning("%a" % get_angle_to(Vector2.ZERO))

	push_error("3. should appear only once in errors" % [])
	push_error("%a" % get_path())

	var b = true
	assert(b, "should never appear " % [])
	assert(not b, "%a should appear but won't" % get_path().get_name(0))
```