clarified signature: avoid case class with redefined equality;
authorwenzelm
Sat, 17 Dec 2022 19:35:49 +0100
changeset 76671 254964ca1b98
parent 76670 b04d45bebbc5
child 76672 32c0abd35071
clarified signature: avoid case class with redefined equality;
src/Pure/PIDE/document.scala
--- a/src/Pure/PIDE/document.scala	Sat Dec 17 19:19:10 2022 +0100
+++ b/src/Pure/PIDE/document.scala	Sat Dec 17 19:35:49 2022 +0100
@@ -91,6 +91,9 @@
     def bad_header(msg: String): Header = Header(errors = List(msg))
 
     object Name {
+      def apply(node: String, master_dir: String = "", theory: String = ""): Name =
+        new Name(node, master_dir, theory)
+
       val empty: Name = Name("")
 
       object Ordering extends scala.math.Ordering[Name] {
@@ -103,7 +106,7 @@
         Graph.make(entries, symmetric = true)(Ordering)
     }
 
-    sealed case class Name(node: String, master_dir: String = "", theory: String = "") {
+    final class Name private(val node: String, val master_dir: String, val theory: String) {
       override def hashCode: Int = node.hashCode
       override def equals(that: Any): Boolean =
         that match {
@@ -123,8 +126,8 @@
 
       override def toString: String = if (is_theory) theory else node
 
-      def map(f: String => String): Name = copy(f(node), f(master_dir), theory)
-      def map_theory(f: String => String): Name = copy(node, master_dir, f(theory))
+      def map(f: String => String): Name =
+        new Name(f(node), f(master_dir), theory)
 
       def json: JSON.Object.T =
         JSON.Object("node_name" -> node, "theory_name" -> theory)