Conversation
|
@copilot please proceed |
…ase/abstract class param Agent-Logs-Url: https://github.com/dadhi/FastExpressionCompiler/sessions/82c35acc-2d27-4de0-9359-3eb4a7da07c8 Co-authored-by: dadhi <39516+dadhi@users.noreply.github.com>
Done. The root cause was in Fix: In the Added regression test |
Fixes
System.IndexOutOfRangeException(andInvalidProgramExceptionfor non-abstract classes) thrown byCompileFastwhen using implicit conversion operators declared on an abstract or non-abstract base class within a closure.Root Cause
In
TryEmitConvert, theelse if (methodParamType != sourceType)branch unconditionally assumed that whenever the conversion operator's parameter type differs from the source type, it must be aNullable<sourceType>wrapping case. It calledGetNullableConstructor()→type.GetConstructors()[0], but abstract classes have no public constructors, so this returned an empty array →IndexOutOfRangeException. For non-abstract base classes it emitted a wrongnewobjinstruction →InvalidProgramException.Fix
In
src/FastExpressionCompiler/FastExpressionCompiler.cs, updated theelse if (methodParamType != sourceType)branch to only emitNewobjwhenNullable.GetUnderlyingType(methodParamType) == sourceType. For the polymorphic base class case (methodParamTypeis a base type/interface ofsourceType), no additional emit is needed — the value already on the stack is assignment-compatible with the conversion method's parameter.Test
Added regression test
Issue500_IndexOutOfRangeException_with_value_objects_implicit_conversions(registered for bothFastExpressionCompilerandFastExpressionCompiler.LightExpression) covering:InvalidProgramExceptionAll 1672 tests pass.