Skip to content

Fix nullable struct fields defaulting to zero instead of null. - #1384

Merged
Arctis-Fireblight merged 1 commit into
Redot-Engine:masterfrom
mcdubhghlas:bug/nullable-struct
Sep 3, 2026
Merged

Fix nullable struct fields defaulting to zero instead of null.#1384
Arctis-Fireblight merged 1 commit into
Redot-Engine:masterfrom
mcdubhghlas:bug/nullable-struct

Conversation

@mcdubhghlas

@mcdubhghlas mcdubhghlas commented Sep 3, 2026

Copy link
Copy Markdown
Member

Fixes #1379

Summary by CodeRabbit

  • Bug Fixes

    • Nullable typed fields in GDScript structs now default to an uninitialized value rather than the type’s zero value.
    • Nullable fields with explicit defaults continue to use those specified values.
  • Tests

    • Added runtime coverage for nullable fields across several supported types.

@mcdubhghlas
mcdubhghlas requested review from a team September 3, 2026 13:50
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 49e53020-247a-4dd5-b975-c96d515b7af6

📥 Commits

Reviewing files that changed from the base of the PR and between b759f20 and 64c2b07.

⛔ Files ignored due to path filters (1)
  • modules/gdscript/tests/scripts/runtime/features/struct_nullable_field_defaults.out is excluded by !**/*.out
📒 Files selected for processing (2)
  • modules/gdscript/gdscript_analyzer.cpp
  • modules/gdscript/tests/scripts/runtime/features/struct_nullable_field_defaults.gd

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The GDScript analyzer now assigns null Variant defaults to nullable struct fields instead of type zero values. A runtime test covers nullable fields, non-nullable fields, and an explicit nullable default.

Changes

Nullable struct defaults

Layer / File(s) Summary
Default generation and runtime validation
modules/gdscript/gdscript_analyzer.cpp, modules/gdscript/tests/scripts/runtime/features/struct_nullable_field_defaults.gd
The analyzer excludes nullable fields from automatic zero-value construction. The runtime test checks nullable int, Vector2, and Vector3 fields, a non-nullable int, and an explicit nullable default of 5.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to cffab

Nullable GDScript struct fields now default to null while non-nullable and explicitly initialized fields retain their intended values. The change is ready to merge.

Suggested reviewers: arctis-fireblight, generalprotectionfault

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: nullable struct fields now default to null instead of zero values.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Arctis-Fireblight Arctis-Fireblight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Arctis-Fireblight
Arctis-Fireblight merged commit c7b2138 into Redot-Engine:master Sep 3, 2026
16 of 17 checks passed
@DaveTheEggman DaveTheEggman added this to the Redot 26.3 milestone Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uninitialized nullable primitive static types in struct are not initialized to null

3 participants