From 0912b0fd0c355cb812beecb60f2d50fff8747491 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 3 Nov 2025 15:07:46 +0100 Subject: [PATCH 1/3] Do not assume left is non-null if another branch is null --- .../collection/immutable/RedBlackTree.scala | 4 ++-- tests/run/sorted-sets-ok.scala | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/run/sorted-sets-ok.scala diff --git a/library/src/scala/collection/immutable/RedBlackTree.scala b/library/src/scala/collection/immutable/RedBlackTree.scala index b343d521a83c..8582ee0bb4fb 100644 --- a/library/src/scala/collection/immutable/RedBlackTree.scala +++ b/library/src/scala/collection/immutable/RedBlackTree.scala @@ -1201,8 +1201,8 @@ private[collection] object RedBlackTree { } } - private def splitLast[A, B](t: Tree[A, B]): (Tree[A, B], A, B) = - if(t.right eq null) (t.left.nn, t.key, t.value) + private def splitLast[A, B](t: Tree[A, B]): (Tree[A, B] | Null, A, B) = + if (t.right eq null) (t.left, t.key, t.value) else { val (tt, kk, vv) = splitLast(t.right.nn) (join(t.left, t.key, t.value, tt), kk, vv) diff --git a/tests/run/sorted-sets-ok.scala b/tests/run/sorted-sets-ok.scala new file mode 100644 index 000000000000..088c1a848fb8 --- /dev/null +++ b/tests/run/sorted-sets-ok.scala @@ -0,0 +1,19 @@ +import scala.collection.SortedSet +import scala.collection.immutable.{SortedSet => ISortedSet} +import scala.collection.mutable.{SortedSet => MSortedSet} + +@main def test = + val s1: SortedSet[Int] = SortedSet(1, 2, 3) + println(s1) + val s2 = s1.filter(_ % 2 == 1) + println(s2) + + val s3: ISortedSet[Int] = ISortedSet(1, 2, 3) + println(s3) + val s4 = s3.filter(_ % 2 == 1) + println(s4) + + val s5: MSortedSet[Int] = MSortedSet(4, 5, 6) + println(s5) + val s6 = s5.filter(_ % 2 == 0) + println(s6) \ No newline at end of file From b9e40bc2ba770a140a3ed195a89b18ce38646d29 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 3 Nov 2025 16:49:03 +0100 Subject: [PATCH 2/3] Try to fix sjs testing --- tests/run/sorted-sets-ok.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run/sorted-sets-ok.scala b/tests/run/sorted-sets-ok.scala index 088c1a848fb8..6941be52a518 100644 --- a/tests/run/sorted-sets-ok.scala +++ b/tests/run/sorted-sets-ok.scala @@ -2,7 +2,7 @@ import scala.collection.SortedSet import scala.collection.immutable.{SortedSet => ISortedSet} import scala.collection.mutable.{SortedSet => MSortedSet} -@main def test = +@main def test(): Unit = val s1: SortedSet[Int] = SortedSet(1, 2, 3) println(s1) val s2 = s1.filter(_ % 2 == 1) From 82c0948f634067f5d42497c91f53dd1b12d18349 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Mon, 3 Nov 2025 18:06:26 +0100 Subject: [PATCH 3/3] Update test name in sorted-sets-ok.scala --- tests/run/sorted-sets-ok.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run/sorted-sets-ok.scala b/tests/run/sorted-sets-ok.scala index 6941be52a518..5fa43e073419 100644 --- a/tests/run/sorted-sets-ok.scala +++ b/tests/run/sorted-sets-ok.scala @@ -2,7 +2,7 @@ import scala.collection.SortedSet import scala.collection.immutable.{SortedSet => ISortedSet} import scala.collection.mutable.{SortedSet => MSortedSet} -@main def test(): Unit = +@main def Test(): Unit = val s1: SortedSet[Int] = SortedSet(1, 2, 3) println(s1) val s2 = s1.filter(_ % 2 == 1)