diff --git a/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt b/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt index 1c9e1dc1..a5331ab4 100644 --- a/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt +++ b/strikt-core/src/main/kotlin/strikt/assertions/Iterable.kt @@ -692,8 +692,8 @@ fun , E> Builder.containsWithOrderingConstraints( } val assertNoFurtherElements = builder.expectsNoFurtherElements || - // Check if the last section has a `last` constraint - allSections.last().elementsWithConstraints.any { it.constraints.any { it == OrderingConstraint.Last } } + // Check if the last section explicitly defines the end element + allSections.last().endDefinedBy is SectionAssertionSpec.EndDefinition.DeclaredElement<*> if (assertNoFurtherElements) { assert("contains no further elements", expected = emptyList()) { if (elementsConsumed == it.count()) {