@@ -1947,40 +1947,41 @@ void GDScriptAnalyzer::decide_suite_type(GDScriptParser::Node *p_suite, GDScript
19471947}
19481948
19491949#ifdef DEBUG_ENABLED
1950- void GDScriptAnalyzer::check_access_private_member (GDScriptParser::IdentifierNode *p_identifier, const bool p_is_call) {
1950+ void GDScriptAnalyzer::check_access_private_member (GDScriptParser::IdentifierNode *p_identifier, const GDScriptParser::DataType &p_datatype, const bool p_is_call) {
19511951 if (p_identifier == nullptr ) {
19521952 return ;
19531953 }
19541954 if (!String (p_identifier->name ).begins_with (" _" )) {
19551955 return ;
19561956 }
1957- if (parser-> current_class -> get_datatype () .kind != GDScriptParser::DataType::CLASS && parser-> current_class -> get_datatype () .kind != GDScriptParser::DataType::SCRIPT) {
1958- return ;
1957+ if (p_datatype .kind != GDScriptParser::DataType::Kind:: CLASS && p_datatype .kind != GDScriptParser::DataType::Kind ::SCRIPT) {
1958+ return ; // Accessing from self
19591959 }
1960+ /* if (parser->current_class->get_datatype().kind != GDScriptParser::DataType::CLASS && parser->current_class->get_datatype().kind != GDScriptParser::DataType::SCRIPT) {
1961+ return;
1962+ }*/
19601963 if (parser->current_function && parser->current_function ->body && parser->current_function ->body ->has_local (p_identifier->name )) {
19611964 return ;
19621965 }
19631966
1964- if (parser->current_class ->has_member (p_identifier->name )) {
1965- if (!p_is_call) {
1966- return ;
1967- }
1968- if (ClassDB::has_method (parser->current_class ->get_datatype ().native_type , p_identifier->name )) {
1969- // Ready to implement CALLING_NATIVE_VIRTUAL_METHOD, but here as a comment temporarily
1970- // parser->push_warning(p_identifier, GDScriptWarning::CALLING_NATIVE_VIRTUAL_METHOD, p_identifier->name);
1971- }
1967+ GDScriptParser::DataType target_resolved = type_from_metatype (p_datatype);
1968+ bool target_has_member = target_resolved.class_type != nullptr && !target_resolved.class_type ->has_member (p_identifier->name );
1969+ if (!target_has_member && p_is_call && !ClassDB::has_method (target_resolved.native_type , p_identifier->name )) {
1970+ return ; // Accessing an inexisting method
1971+ }
1972+ if (is_type_compatible (p_datatype, parser->current_class ->get_datatype (), true )) {
19721973 return ;
19731974 }
19741975
1975- GDScriptParser::ClassNode *base_class = parser->current_class ->base_type .class_type ;
1976+ parser->push_warning (p_identifier, p_is_call ? GDScriptWarning::CALLING_PRIVATE_METHOD : GDScriptWarning::ACCESS_PRIVATE_MEMBER, p_identifier->name );
1977+
1978+ /* GDScriptParser::ClassNode *base_class = parser->current_class->base_type.class_type;
19761979 while (base_class != nullptr) {
19771980 if (base_class->has_member(p_identifier->name)) {
19781981 return;
19791982 }
19801983 base_class = base_class->base_type.class_type;
1981- }
1982-
1983- parser->push_warning (p_identifier, p_is_call ? GDScriptWarning::CALLING_PRIVATE_METHOD : GDScriptWarning::ACCESS_PRIVATE_MEMBER, p_identifier->name );
1984+ }*/
19841985}
19851986#endif // DEBUG_ENABLED
19861987
@@ -3556,15 +3557,15 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
35563557
35573558#ifdef DEBUG_ENABLED
35583559 GDScriptParser::IdentifierNode *identifier = static_cast <GDScriptParser::IdentifierNode *>(p_call->callee );
3559- check_access_private_member (identifier, true );
3560+ check_access_private_member (identifier, p_call-> get_datatype (), true );
35603561#endif
35613562 } else if (callee_type == GDScriptParser::Node::IDENTIFIER) {
35623563 base_type = parser->current_class ->get_datatype ();
35633564 base_type.is_meta_type = false ;
35643565 is_self = true ;
35653566#ifdef DEBUG_ENABLED
35663567 GDScriptParser::IdentifierNode *identifier = static_cast <GDScriptParser::IdentifierNode *>(p_call->callee );
3567- check_access_private_member (identifier, true );
3568+ check_access_private_member (identifier, p_call-> get_datatype (), true );
35683569#endif
35693570 } else if (callee_type == GDScriptParser::Node::SUBSCRIPT) {
35703571 GDScriptParser::SubscriptNode *subscript = static_cast <GDScriptParser::SubscriptNode *>(p_call->callee );
@@ -3600,7 +3601,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
36003601 is_self = subscript->base ->type == GDScriptParser::Node::SELF;
36013602 }
36023603#ifdef DEBUG_ENABLED
3603- check_access_private_member (subscript->attribute , true );
3604+ check_access_private_member (subscript->attribute , subscript-> base -> get_datatype (), true );
36043605#endif
36053606 } else {
36063607 // Invalid call. Error already sent in parser.
@@ -4525,7 +4526,7 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident
45254526 }
45264527
45274528#ifdef DEBUG_ENABLED
4528- check_access_private_member (p_identifier);
4529+ check_access_private_member (p_identifier, p_identifier-> get_datatype () );
45294530#endif
45304531
45314532 return ;
@@ -4891,7 +4892,7 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri
48914892 }
48924893
48934894#ifdef DEBUG_ENABLED
4894- check_access_private_member (p_subscript->attribute );
4895+ check_access_private_member (p_subscript->attribute , p_subscript-> base -> get_datatype () );
48954896#endif
48964897 } else {
48974898 if (p_subscript->index == nullptr ) {
0 commit comments