Skip to content

Conversation

@aksh08022006
Copy link

Fix fcoalesce Date / IDate handling and scalar safety

This PR fixes incorrect behavior and memory safety issues in fcoalesce() when
mixing Date and IDate inputs.

What was wrong

  • fcoalesce(Sys.Date(), as.IDate(...)) errored due to incompatible storage
  • Scalar fallbacks for logical / integer / numeric could return garbage values
  • In some cases this led to incorrect results or segfaults in the test suite

What this PR does

  • Normalizes any Date / IDate combination to Date with REAL storage
  • Uses char_Date / char_IDate consistently (no invalid class assignment)
  • Preserves existing semantics for non-date vectors
  • Fixes scalar fallback handling to avoid uninitialized reads

Tests

  • Added regression tests covering:
    • Date + IDate → Date
    • IDate NA fallback
    • Reversed argument order

All existing tests pass locally and in CI.

Closes: #7545

@jangorecki
Copy link
Member

@aksh08022006 did you use AI when preparing this PR?

@aksh08022006
Copy link
Author

@aksh08022006 did you use AI when preparing this PR?

yes

@jangorecki
Copy link
Member

Please read https://github.com/Rdatatable/data.table/blob/master/.github/CONTRIBUTING.md#pull-requests-prs
Complete file, take a careful look at Pull requests section.

Next time before submitting PR be sure to test that package builds successfully and also pass R package check.

@jangorecki jangorecki closed this Dec 30, 2025
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.

fcoalesce doesnt play nice w/ date and idate

2 participants