Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,15 @@ private Expression HandleReturnType(Expression finalExpr, List<ParameterExpressi
{
if (typeof(T).IsAssignableFrom(finalExpr.Type))
{
return finalExpr;
// If the expression type is already exactly T, return as-is.
if (finalExpr.Type == typeof(T))
{
return finalExpr;
}

// When the expression type is assignable to T but different (e.g., value type -> object),
// we need an explicit conversion.
return Expression.Convert(finalExpr, typeof(T));
}

if (typeof(T).IsNumeric()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,32 @@ public async Task TestMetrics(string expressionTestFilePath)
await Test(expressionTestFilePath);
}

[Fact]
public void ProbeExpressionParser_ObjectReturnType_AllowsValueTypeResults()
{
// Arrange
var scopeMembers = CreateScopeMembers();
const string json = """
{
"ref": "@duration"
}
""";

// Act
var compiled = ProbeExpressionParser<object>.ParseExpression(json, scopeMembers);
var result = compiled.Delegate(
scopeMembers.InvocationTarget,
scopeMembers.Return,
scopeMembers.Duration,
scopeMembers.Exception,
scopeMembers.Members);

// Assert
Assert.NotNull(result);
Assert.IsType<TimeSpan>(result);
Assert.True(compiled.Errors == null || compiled.Errors.Length == 0);
}

private async Task Test(string expressionTestFilePath)
{
// Arrange
Expand Down
Loading