Skip to content

Commit

Permalink
Merge pull request #12 from skiptools/fix-removeLast
Browse files Browse the repository at this point in the history
Change mutableList.removeLast() to mutableList.removeLast() due to compileSDK 35 issue
  • Loading branch information
marcprux authored Dec 7, 2024
2 parents 77328c0 + 4c15af7 commit 352d3ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Sources/SkipLib/Skip/Collections.kt
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,9 @@ interface BidirectionalCollection<Element>: Collection<Element>, MutableListStor

fun removeLast(): Element {
willMutateStorage()
val lastElement = mutableList.removeLast().sref()
// cannot use removeLast() anymore: https://developer.android.com/about/versions/15/behavior-changes-15#openjdk-api-changes
//val lastElement = mutableList.removeLast().sref()
val lastElement = mutableList.removeAt(mutableList.lastIndex).sref()
didMutateStorage()
return lastElement
}
Expand Down
12 changes: 8 additions & 4 deletions Tests/SkipLibTests/CollectionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,14 @@ final class CollectionsTests: XCTestCase {
}

func testRemoveLast() {
var arr1 = [1, 3, 5]
XCTAssertEqual(5, arr1.removeLast())
XCTAssertEqual(3, arr1.removeLast())
XCTAssertEqual([1], arr1)
var arr = [1, 3, 5]
XCTAssertEqual(5, arr.removeLast())
XCTAssertEqual(3, arr.removeLast())
XCTAssertEqual([1], arr)
XCTAssertEqual(1, arr.popLast())
XCTAssertEqual(nil, arr.popLast())
XCTAssertEqual(0, arr.count)
XCTAssertTrue(arr.isEmpty)
}
}

Expand Down

0 comments on commit 352d3ee

Please sign in to comment.