Skip to content

Fix empty strings crashing lookup_code#1246

Open
U-YumeTsuki wants to merge 1 commit intoRedot-Engine:masterfrom
U-YumeTsuki:editor_bugfix
Open

Fix empty strings crashing lookup_code#1246
U-YumeTsuki wants to merge 1 commit intoRedot-Engine:masterfrom
U-YumeTsuki:editor_bugfix

Conversation

@U-YumeTsuki
Copy link
Copy Markdown
Contributor

@U-YumeTsuki U-YumeTsuki commented May 4, 2026

The fixed bug in question could be replicated as simply as holding ctrl and dragging the mouse around in the code editor

Summary by CodeRabbit

  • Bug Fixes
    • Improved GDScript editor code lookup behavior for edge cases, ensuring proper resolution of empty symbols during code intelligence operations.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Walkthrough

A guard clause is added to GDScriptLanguage::lookup_code() that returns early when p_symbol is empty, setting the result to a Nil class type and bypassing downstream resolution logic.

Changes

Early Guard for Empty Symbol Lookup

Layer / File(s) Summary
Edge Case Handling
modules/gdscript/gdscript_editor.cpp
Early return in lookup_code() when p_symbol is empty; sets r_result.type = LOOKUP_RESULT_CLASS and r_result.class_name = "Nil".

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix empty strings crashing lookup_code' accurately describes the main change—it directly addresses the bug fix for empty strings causing crashes in the lookup_code function, which is the primary purpose of this pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/gdscript/gdscript_editor.cpp`:
- Around line 4305-4309: When p_symbol.is_empty(), do not emit a fake sentinel
result; instead return ERR_CANT_RESOLVE and remove the assignment r_result.type
= ScriptLanguage::LOOKUP_RESULT_CLASS and r_result.class_name = "Nil". Use the
established error code ERR_CANT_RESOLVE for unresolvable symbols (consistent
with other branches that return ERR_CANT_RESOLVE) so callers don't receive an
invalid "Nil" ClassDB name and can handle the unresolved case uniformly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cdadfa9c-3f60-4083-bd89-4a9a0234679c

📥 Commits

Reviewing files that changed from the base of the PR and between c9e566c and 3f916d3.

📒 Files selected for processing (1)
  • modules/gdscript/gdscript_editor.cpp

Comment on lines +4305 to +4309
if (p_symbol.is_empty()) {
r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS;
r_result.class_name = "Nil";
return OK;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the LookupResult struct definition to check default value of `location`.
rg -n "LookupResult" --type cpp -A 20 | grep -A 20 "struct LookupResult"

Repository: Redot-Engine/redot-engine

Length of output: 1167


🏁 Script executed:

cat -n core/object/script_language.h | sed -n '371,430p'

Repository: Redot-Engine/redot-engine

Length of output: 2055


Return ERR_CANT_RESOLVE for an empty symbol instead of OK with a fake "Nil" class

Two concrete problems with the current guard:

  1. OK misrepresents the outcome. There is no resolved symbol here. ERR_CANT_RESOLVE is the established return code for all other unresolvable symbols in this function (line 4647), and all callers already handle it correctly.

  2. "Nil" is not a ClassDB class. While the first caller in gdscript.cpp is shielded by its own ClassDB::class_exists(result.class_name) guard, this relies on every present and future caller independently filtering out a sentinel value that should never have been emitted in the first place.

The early exit correctly prevents any crashes downstream. The improvement is about semantic correctness and avoiding the creation of invalid sentinel results that callers must defensively filter.

🛠️ Proposed fix
 	if (p_symbol.is_empty()) {
-		r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS;
-		r_result.class_name = "Nil";
-		return OK;
+		return ERR_CANT_RESOLVE;
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (p_symbol.is_empty()) {
r_result.type = ScriptLanguage::LOOKUP_RESULT_CLASS;
r_result.class_name = "Nil";
return OK;
}
if (p_symbol.is_empty()) {
return ERR_CANT_RESOLVE;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/gdscript/gdscript_editor.cpp` around lines 4305 - 4309, When
p_symbol.is_empty(), do not emit a fake sentinel result; instead return
ERR_CANT_RESOLVE and remove the assignment r_result.type =
ScriptLanguage::LOOKUP_RESULT_CLASS and r_result.class_name = "Nil". Use the
established error code ERR_CANT_RESOLVE for unresolvable symbols (consistent
with other branches that return ERR_CANT_RESOLVE) so callers don't receive an
invalid "Nil" ClassDB name and can handle the unresolved case uniformly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant