You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After looking into the compiler to try and fix myself: This is caused by the parser (and checker once parser check is removed) not allowing lambdas as values outside of function args. Kinda makes sense I suppose, but on the other hand it doesn't make sense that they aren't allowed anywhere an anonymous function type is already declared. In that case, this is technically not a bug (compiler's doing what it's supposed to do).
This code already exists to block lambdas from just be assigned to values where they shouldn't belong. var := |x,y| x+y would not be allowed, but var = |x,y| x+y would be if mut var := fn(x int, y int) int { return x+y } was declared earlier. Also fixes, the issue mentioned in the original post of struct field values not working.
if exp_sym.kind != .function {
c.error('a lambda expression was used, but `${exp_sym.kind}` was expected', node.pos)
return ast.void_type
}
Describe the bug
Can't use lambda as struct field.
Reproduction Steps
Expected Behavior
Expected code to compile and print the
no_args
const when executed without cli arguments.Current Behavior
Possible Solution
No response
Additional Information/Context
I have a fix for this, but it will allow lambdas anywhere an anonymous function is expected.
V version
V 0.4.1 a685088
Environment details (OS name and version, etc.)
Important
You can vote for this issue using the 👍 reaction. More votes increase the issue's priority
for developers.
Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.
The text was updated successfully, but these errors were encountered: