Can't define types inside functions #11662
Replies: 5 comments
-
I'm afraid there could be a lot of problems if you can define types in functions. These could overwrite each other, causing other parts of the program to stop working. I see no added value in supporting this. |
Beta Was this translation helpful? Give feedback.
-
Both C and Go allow this, I've never personally never used this feature. Any thoughts on the benefits? I guess it allows to define types that are only used in the function, but you can also use unexported module level types. |
Beta Was this translation helpful? Give feedback.
-
One way to handle this is use anonymous functions and structs inside function bodies, and use named types at the module level. |
Beta Was this translation helpful? Give feedback.
-
Rust also allows it: fn main() {
type MyType = u8;
let a: MyType = 100;
println!("{:?}", a);
} Here's an example in Linux |
Beta Was this translation helpful? Give feedback.
-
It has been decided to support this :) |
Beta Was this translation helpful? Give feedback.
-
V version: 0.1.25 87c0155
OS: Ubuntu x86_64
What did you do?
Executed this code:
What did you expect to see?
Program executed without errors.
What did you see instead?
Fails with different error:
This works:
Beta Was this translation helpful? Give feedback.
All reactions