Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 15, 2025

Issue

The ToThaiWords(this int value, bool useEtWithTensOnly) extension method was causing a stack overflow due to infinite recursion. The method was incorrectly calling itself instead of delegating to the long version.

Root Cause

// Before (line 37 in FormatterExtensions.cs)
public static string ToThaiWords(this int value, bool useEtWithTensOnly) 
    => ToThaiWords(value, useEtWithTensOnly);  // calls itself infinitely!

Solution

// After 
public static string ToThaiWords(this int value, bool useEtWithTensOnly) 
    => ToThaiWords((long)value, useEtWithTensOnly);  // properly delegates to long version

Changes Made

  • Fixed infinite recursion by casting int to long and calling the correct overload
  • Added regression tests to prevent future occurrences
  • Updated test project target framework from net6.0 to net8.0 for compatibility

Verification

  • ✅ Stack overflow eliminated - method executes without infinite recursion
  • ✅ All existing tests pass (47 tests) + 4 new regression tests = 51 total tests passing
  • ✅ Manual testing confirms correct Thai text output:
    42.ToThaiWords(true)   // Returns: "สี่สิบสอง"
    101.ToThaiWords(true)  // Returns: "หนึ่งร้อยหนึ่ง"
    1001.ToThaiWords(true) // Returns: "หนึ่งพันหนึ่ง"
  • ✅ Behavior matches the long version exactly
  • ✅ No regressions introduced

The fix follows the existing pattern used by other extension methods in the same class and is minimal and surgical.

Fixes #14.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits July 15, 2025 06:06
Co-authored-by: tiakun <1862558+tiakun@users.noreply.github.com>
…n test

Co-authored-by: tiakun <1862558+tiakun@users.noreply.github.com>
Copilot AI changed the title [WIP] ToThaiWords(this int value, bool useEtWithTensOnly) ทำให้ stack overflow Fix stack overflow in ToThaiWords(int, bool) extension method Jul 15, 2025
Copilot AI requested a review from tiakun July 15, 2025 06:11
Co-authored-by: tiakun <1862558+tiakun@users.noreply.github.com>
Copilot AI requested a review from tiakun July 15, 2025 06:19
@tiakun tiakun marked this pull request as ready for review July 16, 2025 16:28
@tiakun tiakun merged commit fc81f54 into master Sep 26, 2025
1 check 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.

ToThaiWords(this int value, bool useEtWithTensOnly) ทำให้ stack overflow

2 participants