Skip to content

Ошибка в операции с датой#1692

Merged
EvilBeaver merged 3 commits into
EvilBeaver:developfrom
Mr-Rm:v2/native/fix-dynamic
Jun 1, 2026
Merged

Ошибка в операции с датой#1692
EvilBeaver merged 3 commits into
EvilBeaver:developfrom
Mr-Rm:v2/native/fix-dynamic

Conversation

@Mr-Rm
Copy link
Copy Markdown
Collaborator

@Mr-Rm Mr-Rm commented May 31, 2026

  1. Вычитание вместо сложения!
  2. Второй операнд может конвертироваться в число из другого типа

Summary by CodeRabbit

  • Bug Fixes

    • Fixed date arithmetic so adding or subtracting dates and numbers produces correct, consistent results (mixed date/number operations now behave as expected).
  • Refactor

    • Simplified and modernized internal date/number operation logic and updated helper implementations for clearer, more maintainable behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6abe7fbc-6e75-4130-ad3b-8ae17aed4c0a

📥 Commits

Reviewing files that changed from the base of the PR and between 7f3a4dc and 09a5044.

📒 Files selected for processing (1)
  • src/OneScript.Native/Runtime/DynamicOperations.cs

📝 Walkthrough

Walkthrough

Fixes date addition in DynamicOperations.Add to add numeric values to BslDateValue correctly and refactors DynamicOperations.Subtract to simplify date-vs-date and date-vs-numeric subtraction paths, with a numeric fallback.

Changes

Date operations changes

Layer / File(s) Summary
Date addition operator and constraint fix
src/OneScript.Native/Runtime/DynamicOperations.cs
DynamicOperations.Add now computes bslDate + (decimal)right for BslDateValue left operands and no longer requires right to be BslNumericValue.
Date subtraction refactor
src/OneScript.Native/Runtime/DynamicOperations.cs
DynamicOperations.Subtract now returns BslNumericValue.Create(date - dateRight) for date-date, BslDateValue.Create(date - (decimal)right) for date-other, and otherwise falls back to numeric subtraction (decimal)left - (decimal)right.
Helpers, wrapping and guards modernized
src/OneScript.Native/Runtime/DynamicOperations.cs
WrapClrObjectToValue reformatted with pattern-based mapping; several helper methods converted to expression-bodied forms; GetIndexedValue call no longer casts to (IValue); runtime-context guards use is not pattern negation.

Sequence Diagram(s)

(see hidden review stack artifact for sequence diagrams visualizing Add and Subtract flows)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • nixel2007

Poem

🐰 I nibbled numbers by the moonlit gate,
Dates and decimals in a tiny fête.
Addition fixed—no subtraction trace,
Subtract refined, each value in its place.
Hooray, the calendar hops with grace! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Ошибка в операции с датой' (Error in date operation) accurately describes the main change: fixing incorrect date arithmetic behavior where addition was performing subtraction instead.
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

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.

@Mr-Rm Mr-Rm requested a review from EvilBeaver May 31, 2026 11:43
var foundType = manager.GetTypeByName(name);
return new BslTypeValue(foundType);
}
=> new(manager.GetTypeByName(name));
Copy link
Copy Markdown
Owner

@EvilBeaver EvilBeaver Jun 1, 2026

Choose a reason for hiding this comment

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

Просьба пояснить эту магию

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Разобрался, это новый синтаксис конструктора new, просто в возвращаемом значении я к нему не привык, обычно они встречаются в инициализации полей..

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  1. убираем временную переменную
-            var foundType = manager.GetTypeByName(name);
-            return new BslTypeValue(foundType);
+           return new BslTypeValue(manager.GetTypeByName(name));
  1. меняем body на lambda
- {
-           return new BslTypeValue(manager.GetTypeByName(name));
- }
+  => new BslTypeValue(manager.GetTypeByName(name));
  1. используем автовывод типа (C#9)
-   => new BslTypeValue(manager.GetTypeByName(name));
+  => new(manager.GetTypeByName(name));

@EvilBeaver EvilBeaver merged commit 273f857 into EvilBeaver:develop Jun 1, 2026
2 checks passed
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.

2 participants