Skip to content

Commit

Permalink
Merge pull request #90580 from vnen/gdscript-allow-enum-to-int-cast
Browse files Browse the repository at this point in the history
GDScript: Allow casting enum to int
  • Loading branch information
akien-mga committed Apr 13, 2024
2 parents 8e1b500 + 030995c commit c9a595a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,8 @@ void GDScriptAnalyzer::reduce_cast(GDScriptParser::CastNode *p_cast) {
if (op_type.builtin_type == Variant::INT && cast_type.kind == GDScriptParser::DataType::ENUM) {
mark_node_unsafe(p_cast);
valid = true;
} else if (op_type.kind == GDScriptParser::DataType::ENUM && cast_type.builtin_type == Variant::INT) {
valid = true;
} else if (op_type.kind == GDScriptParser::DataType::BUILTIN && cast_type.kind == GDScriptParser::DataType::BUILTIN) {
valid = Variant::can_convert(op_type.builtin_type, cast_type.builtin_type);
} else if (op_type.kind != GDScriptParser::DataType::BUILTIN && cast_type.kind != GDScriptParser::DataType::BUILTIN) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# GH-85882

enum Foo { A, B, C }

func test():
var a := Foo.A
var b := a as int + 1
print(b)

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_OK
1

0 comments on commit c9a595a

Please sign in to comment.