[swift-users] Request advice on closed range operator
Peter van der Linden
pvdl at afu.com
Sun Feb 14 11:37:29 CST 2016
Hi,
I'm a swift novice, possibly asking an elementary question.
I noticed that in some cases, a closed range produces a compiler error
message.
If you add whitespace before and after the closed range operator (in the
example below), the error message goes away.
If you delete whitespace before and after the closed range operator, the
error message also goes away.
If you have a space before the closed range operator, but not one after,
you get an error message.
If you have a space after the closed range operator, but not one before,
you get an error message.
Below is a small example that demonstrates the error. Can anyone
explain more about this? I find it unusual that adding white space
between two tokens can cause the compiler to emit an error message.
Should I file a bug about this?
Thanks
Peter
pvdl$ swift
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15
clang-700.1.81). Type :help for assistance.
1> let s1 = "foo"
2. let i = s1.startIndex
3. let j = s1.startIndex.advancedBy(1)
s1: String = "foo"
i: Index = {
_base = {
_position = 0
_core = {
_baseAddress = 0x000000010054d680
_countAndFlags = 3
_owner = nil
}
}
_lengthUTF16 = 1
}
j: Index = {
_base = {
_position = 1
_core = {
_baseAddress = 0x000000010054d680
_countAndFlags = 3
_owner = nil
}
}
_lengthUTF16 = 1
}
4> var s2 = s1[ i ...j ]
repl.swift:4:16: error: expected ',' separator
var s2 = s1[ i ...j ]
^
,
4> var s2 = s1[ i...j ]
s2: String = "fo"
5> var s3 = s1[ i... j ]
repl.swift:5:27: error: expected ',' separator
var s3 = s1[ i... j ]
^
,
More information about the swift-users
mailing list