Skip to content

Commit c9a595a

Browse files
committed
Merge pull request godotengine#90580 from vnen/gdscript-allow-enum-to-int-cast
GDScript: Allow casting enum to int
2 parents 8e1b500 + 030995c commit c9a595a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,6 +3469,8 @@ void GDScriptAnalyzer::reduce_cast(GDScriptParser::CastNode *p_cast) {
34693469
if (op_type.builtin_type == Variant::INT && cast_type.kind == GDScriptParser::DataType::ENUM) {
34703470
mark_node_unsafe(p_cast);
34713471
valid = true;
3472+
} else if (op_type.kind == GDScriptParser::DataType::ENUM && cast_type.builtin_type == Variant::INT) {
3473+
valid = true;
34723474
} else if (op_type.kind == GDScriptParser::DataType::BUILTIN && cast_type.kind == GDScriptParser::DataType::BUILTIN) {
34733475
valid = Variant::can_convert(op_type.builtin_type, cast_type.builtin_type);
34743476
} else if (op_type.kind != GDScriptParser::DataType::BUILTIN && cast_type.kind != GDScriptParser::DataType::BUILTIN) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# GH-85882
2+
3+
enum Foo { A, B, C }
4+
5+
func test():
6+
var a := Foo.A
7+
var b := a as int + 1
8+
print(b)
9+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GDTEST_OK
2+
1

0 commit comments

Comments
 (0)