swift-parsing icon indicating copy to clipboard operation
swift-parsing copied to clipboard

Fix an error message StartsWith parser throws

Open pinkjuice66 opened this issue 1 year ago • 0 comments

The Problem

StartsWith parser don't produce an error message as documented when failed.

스크린샷 2023-12-06 오전 1 52 04

Above code produce a below error message which has a wired type presented at expected value position. 스크린샷 2023-12-06 오전 1 49 05

Causes

StartsWith parser hold possiblePrefix value as AnyCollection type, so it would lose its original type. It could be problematic when the possiblePrefix value was passed as argument to formatting function, because formatting function dosen't handle AnyCollection type as its input type. It only cares about String related type so type erased AnyCollection<UInt8> will be always formatted as it's own Type name.

Fixs

  • Holds possiblePrefix value with Any type, so it can preserve it's own type and pass it when we need to format that value.

Alternatives

  • Add new generic 'PossiblePrefix' to StartsWith
    • It will add more complexity to whole StartsWith type.
  • Let formatting function handle AnyCollection Type as its input.
    • We should handle other edge cases like when our original intention was to leave it as it is but AnyCollection with UInt8 Element unexpectedly converts to String.

pinkjuice66 avatar Dec 05 '23 17:12 pinkjuice66