Hi, after we updated to version 1.4.0 of parlot we started to get System.InvalidCastException : Object must implement IConvertible. exceptions in the code. It looks like it happens when using .Then<T>() where T is not IConvertible. Was this intentional, that Then now requires a IConvertible to discard the result?
Here is a snippet of test code which now fails after 1.4.0. The first case with the // A comment fails, but the other one is ok.
using Parlot.Fluent;
using static Parlot.Fluent.Parsers;
public class TestClass
{
[Theory]
[InlineData("""
// A Comment
var a = 'test'
""")]
[InlineData("""
var a = 'test'
""")]
public void SimpleTest(string testString)
{
var commentParser = Terms.Text("//").And(AnyCharBefore(OneOf(Literals.Char('\n'), Literals.Char('\r'))));
var varKeyword = Terms.Text("var");
var identifier = Terms.Identifier();
var equal = Terms.Char('=');
var str = Terms.String();
var expressionParser = varKeyword.And(identifier).And(equal).And(str).Then<BaseExp?>(a => new AssignExpression(a.Item2.ToString()!, a.Item4.ToString()!));
var simpleParser = OneOf(commentParser.Then<BaseExp>(), expressionParser);
var result = simpleParser.Parse(testString);
}
public abstract record BaseExp;
public record AssignExpression(string Name, string Value) : BaseExp;
}
We were able to work around it by calling .Then(default(BaseExp)) instead, for ignoring the value
Hi, after we updated to version 1.4.0 of parlot we started to get
System.InvalidCastException : Object must implement IConvertible.exceptions in the code. It looks like it happens when using.Then<T>()whereTis not IConvertible. Was this intentional, thatThennow requires a IConvertible to discard the result?Here is a snippet of test code which now fails after 1.4.0. The first case with the
// A commentfails, but the other one is ok.We were able to work around it by calling
.Then(default(BaseExp))instead, for ignoring the value