fix #1602: преобразование ЭлементСпискаЗначений в строку - #1606
Conversation
WalkthroughThis PR adds a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs(1 hunks)tests/value-list.os(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-01T08:10:34.187Z
Learnt from: Mr-Rm
Repo: EvilBeaver/OneScript PR: 1456
File: src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs:308-308
Timestamp: 2024-10-01T08:10:34.187Z
Learning: Если метод `ToString()` обеспечивает достаточное представление константы, возможно, хранение поля `presentation` не требуется.
Applied to files:
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs
🧬 Code graph analysis (1)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs (1)
src/ScriptEngine/Machine/ValueFactory.cs (1)
ValueFactory(17-175)
🔇 Additional comments (6)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs (4)
31-31: LGTM!The simplification to an auto-property is appropriate and maintains the same functionality.
36-37: LGTM!The expression-bodied syntax with null-coalescing operator correctly normalizes null values to empty strings while maintaining the same behavior.
41-41: LGTM!The simplification to an auto-property is appropriate.
46-47: LGTM!The expression-bodied syntax with null-coalescing operator correctly normalizes null values to undefined values via
ValueFactory.Create().tests/value-list.os (2)
22-22: LGTM!The new test is correctly added to the test collection with consistent naming.
397-413: Excellent test coverage!The test comprehensively covers the string conversion behavior including edge cases:
- No presentation specified (falls back to value)
- Empty presentation (falls back to value)
- Undefined presentation (normalized and falls back to value)
- Space presentation (preserved as presentation)
| public override string ToString() | ||
| => !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value.ToString(); |
There was a problem hiding this comment.
Add null check for Value to prevent NullReferenceException.
If Value is null, calling Value.ToString() will throw a NullReferenceException. Since Value is not initialized in the constructor and is a settable property, it can be null.
Apply this diff to add a null check:
public override string ToString()
- => !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value.ToString();+ => !String.IsNullOrEmpty(_presentationHolder) ? _presentationHolder : Value?.ToString() ?? String.Empty;📝 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.
| publicoverridestringToString() | |
| =>!String.IsNullOrEmpty(_presentationHolder)?_presentationHolder:Value.ToString(); | |
| publicoverridestringToString() | |
| =>!String.IsNullOrEmpty(_presentationHolder)?_presentationHolder:Value?.ToString()??String.Empty; |
🤖 Prompt for AI Agents
In src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs around
lines 50-51, the ToString() implementation calls Value.ToString() which can
throw a NullReferenceException if Value is null; change the logic so it returns
_presentationHolder if present, otherwise if Value is non-null return
Value.ToString(), and if Value is null return an empty string (or another safe
default) to avoid the exception.
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
Improvements
Tests