Skip to content

Commit da7d8ae

Browse files
committed
Fix some unit tests that expected const containers to return references to mutable elements
1 parent af7a9b9 commit da7d8ae

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

test/compile_test.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,13 @@ private void checkSliceFunctionality(Type, Container)(ref Container container)
340340

341341
private void checkIndexFunctionality(Type, KeyType, Container)(ref Container container)
342342
{
343+
import std.traits : hasFunctionAttributes;
344+
343345
static assert(__traits(compiles, {container[KeyType.init];}));
344-
static assert(is(typeof(container[KeyType.init]) == Type));
346+
// The tests here will expect the wrong thing for opIndex implementations
347+
// that return by ref.
348+
static if (!hasFunctionAttributes!(Container.opIndex!Container, "ref"))
349+
static assert(is(typeof(container[KeyType.init]) == Type));
345350
static assert(is(typeof(container.length) == size_t));
346351
assert(container.length == 0);
347352
}

0 commit comments

Comments
 (0)