@@ -1511,23 +1511,30 @@ $(GNAME Slice):
1511
1511
$(H3 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
1512
1512
1513
1513
$(P If the slice bounds can be known at compile time, the slice expression
1514
- may be implicitly convertible to an lvalue of static array. For example:)
1514
+ may be implicitly convertible to a static array lvalue . For example:)
1515
1515
1516
1516
-------------
1517
1517
arr[a .. b] // typed T[]
1518
1518
-------------
1519
1519
1520
+ $(P
1520
1521
If both $(CODE a) and $(CODE b) are integers (which may be constant-folded),
1521
1522
the slice expression can be converted to a static array of type
1522
1523
$(D T[b - a]).
1524
+ )
1525
+ $(NOTE a static array can also be $(DDSUBLINK spec/arrays, assignment,
1526
+ assigned from a slice), performing a runtime check that the lengths match.)
1523
1527
1524
- $(SPEC_RUNNABLE_EXAMPLE_RUN
1528
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1525
1529
---
1530
+ void f(int[2] sa);
1531
+
1526
1532
int[] arr = [1, 2, 3];
1527
- int[2] sa = arr[1 .. 3];
1533
+ //f(arr); // error, can't convert
1534
+ f(arr[1 .. 3]); // OK
1535
+ //f(arr[0 .. 3]); // error
1528
1536
1529
- assert(sa == [2, 3]);
1530
- //sa = arr[0 .. 3]; // error, cannot match length
1537
+ int[2] g() { return arr[0 .. 2]; }
1531
1538
---
1532
1539
)
1533
1540
@@ -1550,16 +1557,17 @@ $(H3 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
1550
1557
-------------
1551
1558
)
1552
1559
1560
+ $(COMMENT Not implemented yet - https://issues.dlang.org/show_bug.cgi?id=13700
1553
1561
$(P Certain other forms of slice expression can be implicitly converted to a static array
1554
- when the slice length can be known at compile-time.
1562
+ when the slice length can be known at compile-time.)
1555
1563
1556
- $(SPEC_RUNNABLE_EXAMPLE_RUN
1564
+ $(COMMENT SPEC_RUNNABLE_EXAMPLE_RUN
1557
1565
-------------
1558
1566
int[] da = [1, 2, 3];
1559
1567
int i = da[0]; // runtime variable
1560
1568
1561
- int[2] sa = da[i .. i + 2];
1562
- assert(sa == [2, 3]);
1569
+ int[2] f() { return da[i .. i + 2]; }
1570
+ assert(f() == [2, 3]);
1563
1571
-------------
1564
1572
)
1565
1573
@@ -1580,6 +1588,7 @@ $(H3 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
1580
1588
$(TROW $(D arr[e+a .. e+b]), $(D b - a) $(I if) $(D a <= b))
1581
1589
$(TROW $(D arr[e-a .. e-b]), $(D a - b) $(I if) $(D a >= b))
1582
1590
)
1591
+ )
1583
1592
1584
1593
$(H2 $(LNAME2 primary_expressions, Primary Expressions))
1585
1594
0 commit comments