-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typedesc cannot be used as a type converter #8403
Comments
Wierd error message, but doesn't this conversion mean that you want to convert |
@Araq, what? A bound typedesc paramter such as In fact, there is a simpler work-around. The problem goes away if you give the proc sum*[T](s: seq[T], R: typedesc): R =
# sum which aggregates into a different result type
type RR = R
var sum: R = 0
for x in s:
sum += RR(x)
return sum
echo @[1, 2, 3].sum(float) |
Might be related to #7160, but maybe worth tracking on its own. It looks like it is not possible to use typedescs for type conversions:
Errors with
Error: type expected
in the conversion line. The same does work with genericsbut this is much less elegant in some API design cases (e.g. in this case because having an overload
sum[T]
(implicit return type) andsum[T, R]
(explicit return type) overload at the same time would be disallowed due to result type overloading).I just noticed that there is a simple work-around for the issue though, which indicates that this is probably not a fundamental issue with typedescs. Introducing a dummy generic works:
The text was updated successfully, but these errors were encountered: