1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

GDScript: Use "is" keyword for type checking.

Replaces the `extends` keyword with `is` in the context of testing for type compatibility.
`extends` is still used for declaring class inheritance.

Example:

```gdscript
extends Node2D

func _input(ev):
	if ev is InputEventKey:
		print("yay, key event")
```
This commit is contained in:
Andreas Haas
2017-05-26 19:45:39 +02:00
parent f89641907f
commit 015d36d18b
7 changed files with 12 additions and 8 deletions

View File

@@ -1077,7 +1077,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break;
case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break;
case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break;
case GDTokenizer::TK_PR_EXTENDS: op = OperatorNode::OP_EXTENDS; break;
case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break;
case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break;
case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break;
default: valid = false; break;
@@ -1117,7 +1117,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
switch (expression[i].op) {
case OperatorNode::OP_EXTENDS:
case OperatorNode::OP_IS:
priority = -1;
break; //before anything
@@ -1420,7 +1420,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) {
}
}
if (op->op == OperatorNode::OP_EXTENDS) {
if (op->op == OperatorNode::OP_IS) {
//nothing much
return op;
}