1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-06 17:25:19 +00:00

Merge pull request #73203 from dalexeev/gds-fix-num-literal

GDScript: Fix repeated `_` are allowed after decimal point
This commit is contained in:
Rémi Verschelde
2023-06-15 15:26:09 +02:00
7 changed files with 88 additions and 15 deletions

View File

@@ -1,3 +1,3 @@
func test():
# Number separators may not be placed right next to each other.
var __ = 1__23
var _num = 1__23

View File

@@ -1,2 +1,2 @@
GDTEST_PARSER_ERROR
Only one underscore can be used as a numeric separator.
Multiple underscores cannot be adjacent in a numeric literal.

View File

@@ -0,0 +1,3 @@
func test():
# Number separators may not be placed right next to each other.
var _num = 123.45__67

View File

@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Multiple underscores cannot be adjacent in a numeric literal.

View File

@@ -1,12 +1,26 @@
func test():
# `_` can be used as a separator for numbers in GDScript.
# It can be placed anywhere in the number, except at the beginning.
# Currently, GDScript in the `master` branch only allows using one separator
# per number.
# Results are assigned to variables to avoid warnings.
var __ = 1_23
__ = 123_ # Trailing number separators are OK.
__ = 12_3
__ = 123_456
__ = 0x1234_5678
__ = 0b1001_0101
print(1_23)
print(12_3)
print(1_2_3)
print(123_) # Trailing number separators are OK.
print(123_456)
print(123_45_6_)
print("---")
print(0x1234_00ff)
print(0x1234_00_f_f_)
print(0b1001_0101)
print(0b1001_01_0_1_)
print("---")
print(-1_234.456_7)
print(-1_23_4_.4_56_7_)
print(-1_234.)
print(-1_23_4_.)
print(.456_7)
print(.4_56_7_)
print("---")
print(-1_234.5e000_3)
print(-1_23_4_.5e0_00_3_)
print(-1_234.5e+000_3)
print(-1_23_4_.5e+0_00_3_)

View File

@@ -1 +1,24 @@
GDTEST_OK
123
123
123
123
123456
123456
---
305398015
305398015
149
149
---
-1234.4567
-1234.4567
-1234
-1234
0.4567
0.4567
---
-1234500
-1234500
-1234500
-1234500