Skip to content

Commit 98267f4

Browse files
authored
Adjust lightScope label handling (libmir#478)
1 parent 3729b5c commit 98267f4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

source/mir/ndslice/slice.d

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ public:
966966
/// ditto
967967
auto lightScope()() return scope immutable @property
968968
{
969-
auto ret = Slice!(LightImmutableOf!(LightScopeOf!Iterator), N, kind, staticMap!(LightImmutableOfLightConstOf(Labels)))
969+
auto ret = Slice!(LightImmutableOf!(LightScopeOf!Iterator), N, kind, staticMap!(LightImmutableOfLightConstOf, Labels))
970970
(_structure, .lightScope(_iterator));
971971
foreach(i; Iota!L)
972972
ret._labels[i] = .lightScope(_labels[i]);
@@ -4156,3 +4156,21 @@ unittest
41564156
row[3] = 6;
41574157
assert(matrix[2, 3] == 6); // D & C index order
41584158
}
4159+
4160+
// Test fix to issue #470
4161+
@safe pure nothrow @nogc
4162+
version(mir_ndslice_test)
4163+
unittest
4164+
{
4165+
import mir.ndslice.slice: LightImmutableOfLightConstOf, Slice, Contiguous;
4166+
import std.meta: staticMap;
4167+
// Make `x` immutable with label to ensure trigger of staticMap with immutable lightScope overload
4168+
alias T = Slice!(int*, 2, Contiguous, int*);
4169+
immutable T x = T.init;
4170+
// For compilation of immutable lightScope overload with auto return type inference
4171+
alias R = typeof(x.lightScope);
4172+
// Ensure `R` is a Slice
4173+
static assert(is(T : Slice!(Iterator, 2, Contiguous), Iterator));
4174+
// Ensure staticMap working properly
4175+
static assert(is(R.Labels[0] == staticMap!(LightImmutableOfLightConstOf, int*)[0]));
4176+
}

0 commit comments

Comments
 (0)