When querying the SQL functions listed at the bottom of the post with these statements, the first will not work and the second will work correctly.
foo(1).Dump();
foo2(2).Dump();
The first function (from the two listed below) will have SQL generated that looks like
-- Region Parameters
DECLARE @p0 Int = 1
-- EndRegion
SELECT [t0].@Max AS [Max]
FROM [dbo].[foo](@p0) AS [t0]
which is incorrect. If you inspect the SELECT statement closely you will see
[t0].@Max
and the @ symbol should not be there.The following SQL function definitions are referenced above: