[indexFrom..<indexTo] error 'Parameter 1 should be Int32'

Even though I define the first parameter correctly I am getting this error. Is there an issue with the runtime library?

var indexFrom, indexTo: Int32

string1 = string2[indexFrom..<indexTo]

Hmm, this is strange, but i can reproduce the issue (i tried on .NET).

the Swift Base Librray does defne

    public subscript(_ range: Range) -> NativeString {
    }

but i can’t call it

var r: Swift.Range = indexFrom..<indexTo

var string3 = string2[r] // E486 Parameter 1 is "Swift.Range", should be "Int32", in call to String!.get_Chars(_ aIndex: Int32) -> Char
var string1 = string2[indexFrom..<indexTo] // E486 Parameter 1 is "Swift.Range", should be "Int32", in call to String!.get_Chars(_ aIndex: Int32) -> Char

I’ll log a bug for the compiler team.

Oh wait, i got it: it seems you have the RemObjects.Elements.RTL namespace in the importss (either in your source file or in the project Default Uses Clause setting).

RemObjects.Elements.RTL introduces its own String type (designed for platform and language interoperability) and the Swift-specific extensions to String are not available on that type (by design).

If you want to use Elements RTL, you’ll need ot use its conventions for dealing with strings (ie string2.Substring(indexFrom, indexTo-indexFrom)); if you don’t drop RemObjects.Elements.RTL from the uses clause (and maybe even remove the “Elements” reference form the project, as well.

Does that make sense?

Makes sense and your suggestion resolved the issue.

1 Like