     // dispatching to the minimal selector for the supplied options.
     // So let's do that; the switch should compile away anyhow.
     return locale != nil ? _ns.compare(
-      aString, options: mask,
-      range: _toNSRange(range ?? self.characters.indices),
-      locale: locale)
+      aString,
+      options: mask,
+      range: _toNSRange(
+        range ?? self.characters.startIndex..<self.characters.endIndex
+      ),
+      locale: locale
+    )
 
     : range != nil ? _ns.compare(
       aString,
       options: mask,
-      range: _toNSRange(range ?? self.characters.indices))
+      range: _toNSRange(range!)
+    )
 
     : !mask.isEmpty ? _ns.compare(aString, options: mask)
 

      of: target,
      with: replacement,
      options: options,
      range: _toNSRange(searchRange ?? self.characters.indices)
    )
    : _ns.replacingOccurrences(of: target, with: replacement)
  }

      locale != nil ? _ns.range(
        of: aString,
        options: mask,
        range: _toNSRange(
          searchRange ?? self.characters.startIndex..<self.characters.endIndex
        ),
        locale: locale
      )
      : searchRange != nil ? _ns.range(
