@@ -2025,6 +2025,19 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context,
20252025
20262026 } while ((multiline || previous.type == GDScriptTokenizer::Token::SEMICOLON ) && !check (GDScriptTokenizer::Token::DEDENT ) && !lambda_ended && !is_at_end ());
20272027
2028+ #ifdef DEBUG_ENABLED
2029+ if (current_suite->unreachable_code_start ) {
2030+ Node *unreachable_start = current_suite->unreachable_code_start ;
2031+ Node *unreachable_end = suite->statements [suite->statements .size () - 1 ];
2032+ push_warning (
2033+ unreachable_start->start_line ,
2034+ unreachable_start->start_column ,
2035+ unreachable_end->end_line ,
2036+ unreachable_end->end_column ,
2037+ GDScriptWarning::UNREACHABLE_CODE ,
2038+ current_function->identifier ? current_function->identifier ->name : " <anonymous lambda>" );
2039+ }
2040+ #endif // DEBUG_ENABLED
20282041 complete_extents (suite);
20292042
20302043 if (multiline) {
@@ -2245,7 +2258,12 @@ GDScriptParser::Node *GDScriptParser::parse_statement() {
22452258 if (unreachable && result != nullptr ) {
22462259 current_suite->has_unreachable_code = true ;
22472260 if (current_function) {
2248- push_warning (result, GDScriptWarning::UNREACHABLE_CODE , current_function->identifier ? current_function->identifier ->name : " <anonymous lambda>" );
2261+ // Store where the unreachable code begins for this suite,
2262+ // but hold off on emitting the warning until we also know where
2263+ // the unreachable code ends.
2264+ if (current_suite->unreachable_code_start == nullptr ) {
2265+ current_suite->unreachable_code_start = result;
2266+ }
22492267 } else {
22502268 // TODO: Properties setters and getters with unreachable code are not being warned
22512269 }
0 commit comments