Skip to content

Commit

Permalink
regression: static func can't access const fix
Browse files Browse the repository at this point in the history
(cherry picked from commit e7f056d)
  • Loading branch information
ThakeeNathees authored and akien-mga committed May 13, 2020
1 parent dd7f9b1 commit 6d7fb3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7338,7 +7338,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
return return_type;
}

bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type) const {
bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type, bool *r_is_const) const {
DataType base_type = p_base_type;

// Check classes in current file
Expand All @@ -7349,6 +7349,8 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN

while (base) {
if (base->constant_expressions.has(p_member)) {
if (r_is_const)
*r_is_const = true;
r_member_type = base->constant_expressions[p_member].expression->get_datatype();
return true;
}
Expand Down Expand Up @@ -7572,8 +7574,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
base_type = DataType(*p_base_type);
}

if (_get_member_type(base_type, p_identifier, member_type)) {
if (!p_base_type && current_function && current_function->_static) {
bool is_const = false;
if (_get_member_type(base_type, p_identifier, member_type, &is_const)) {
if (!p_base_type && current_function && current_function->_static && !is_const) {
_set_error("Can't access member variable (\"" + p_identifier.operator String() + "\") from a static function.", p_line);
return DataType();
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ class GDScriptParser {
DataType _get_operation_type(const Variant::Operator p_op, const DataType &p_a, const DataType &p_b, bool &r_valid) const;
Variant::Operator _get_variant_operation(const OperatorNode::Operator &p_op) const;
bool _get_function_signature(DataType &p_base_type, const StringName &p_function, DataType &r_return_type, List<DataType> &r_arg_types, int &r_default_arg_count, bool &r_static, bool &r_vararg) const;
bool _get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type) const;
bool _get_member_type(const DataType &p_base_type, const StringName &p_member, DataType &r_member_type, bool *r_is_const = nullptr) const;
bool _is_type_compatible(const DataType &p_container, const DataType &p_expression, bool p_allow_implicit_conversion = false) const;
Node *_get_default_value_for_type(const DataType &p_type, int p_line = -1);

Expand Down

0 comments on commit 6d7fb3d

Please sign in to comment.