Skip to content

parser: use TContext for the context parameter in Evaluate - #28

Merged
rameel merged 1 commit into
mainfrom
parser/evaluate-context-type
Nov 18, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/evaluate-context-type

Conversation

@rameel

@rameel rameel commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Evaluate<TContext, TResult> created the context parameter with the runtime type of the context but compiled a delegate that takes TContext. When the context was an instance of a derived or implementing type, such as Evaluate<IFace, object>("Value", impl), it failed with ParameterExpression of type 'Impl' cannot be used for delegate parameter of type 'IFace'.

This PR creates the parameter with TContext, so the expression can access the members of TContext. Members declared only in the runtime type of the context are not available, as for a variable of type TContext in C#. Virtual members are still dispatched on the runtime type, so Evaluate<object, string>("ToString()", context) calls the override.

Calls where the runtime type of the context is TContext are not affected. The non-generic Evaluate(source, context) still binds the members of the runtime type.

Evaluate<TContext, TResult> created the context parameter with the
runtime type of the context but compiled a delegate that takes
TContext. When the context was an instance of a derived or
implementing type, such as Evaluate<IFace, object>("Value", impl), it
failed with "ParameterExpression of type 'Impl' cannot be used for
delegate parameter of type 'IFace'".

Create the parameter with TContext, so the expression can access the
members of TContext. Members declared only in the runtime type of the
context are not available, as for a variable of type TContext in C#.
@rameel
rameel merged commit ee3ac22 into main Nov 18, 2026
1 check passed
@rameel
rameel deleted the parser/evaluate-context-type branch November 18, 2026 12:28
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.

1 participant