5 ms·
Awesome! I'm going to compile `release-0.6` right now, because I've been having some issues w/ trunk these past few days. Simple things like declaring fixed ve
by drbawb 14y ago
Awesome! I'm going to compile `release-0.6` right now, because I've been having some issues w/ trunk these past few days.
Simple things like declaring fixed vectors won't compile for me: `let numbers: ~[int, ..3] = [1,2,3];` fails to compile saying it expected `~[int * 3] and got ~[<VI2>]`. That's an example straight from the tutorial.
I'm getting segfaults when iterating over a non-fixed vector of owned elements casted to a trait.
(This works fine if I access the elements directly; or use managed pointers. With owned pointers my `len()` method returns the wrong number of elements, which I suspect is breaking the iterators.)
- pcwalton 14y agoThe tutorial examples are run as part of the test suite. The tutorial example in question is `let numbers: [int, ..3] = [1, 2, 3];`, which should work. There are several known compiler bugs with any trait types other than `@Trait`. Please do continue to file any bugs you find, though—all crash bugs are bugs that need to be fixed :)
- drbawb 14y agoWhoops, I did botch up the syntax on my listed example. I compiled release-0.6; and sure enough `let numbers: [int, ..3] = [1,2,3];` compiles. `let numbers: ~[int, ..3] = ~[1,2,3];` does not compile on my system though. Ditto for the @ sigil. (Expected `~[int * 3] but found ~[<VI2>]`) My understanding is that the first example [from the docs] allocates the vector on the stack. My uncompilable examples should be equivalent except that they use the heap for storage. Is there a reason this shouldn't compile? Thanks so much for the reply!
- spicyj 14y agoIn fact you just want: let numbers: ~[int] = ~[1,2,3]; When you allocate a vector on the heap, you don't need to specify the size.
- drbawb 14y agoI was thinking you might have a function that operates on some fixed length vector. For e.g: `fn foo(bar: ~[int, ..3]) { ... }`, and the compiler would enforce that you only pass vectors of length 3 to that function. But since I can't get `~[int, ..3] = ~[1,2,3]` (etc.) to compile that seems to be impossible w/ vectors on the heap?
- spicyj 14y agoI believe you can't do that. You can, however, make a function that only operates on 3-tuples: fn foo(bar: (int, int, int)) { ... }
- pcwalton 14y agoIt's a bug. Sorry about that. For now, write the type as `~([int, ..3])`.
- spicyj 14y agoI stand corrected -- thanks, didn't realize that you could have a pointer to a fixed-length vector.