You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let str = "DEADBEEF"
var result: [UInt8] = []
var pos = str.startIndex
let end = pos.advanced(by: 2)
let byteStr = str[pos..<end]
let byte = UInt8(byteStr, radix: 16)
guard let byte = byte else {
fatalError("could convert \(byteStr) to UInt8")
}
result.append(byte)
But when I wrap it in a while loop, it doesn't compile:
let str = "DEADBEEF"
var result: [UInt8] = []
var pos = str.startIndex
while pos != str.endIndex {
let end = pos.advanced(by: 2)
let byteStr = str[pos..<end]
let byte = UInt8(byteStr, radix: 16)
guard let byte = byte else {
fatalError("could convert \(byteStr) to UInt8")
}
result.append(byte)
pos = end
}
The compiler fails with this error:
$ swift t.swift
t.swift:8:15: error: definition conflicts with previous value
guard let byte = byte else {
^
t.swift:7:9: note: previous definition of 'byte' is here
let byte = UInt8(byteStr, radix: 16)
^
t.swift:11:19: error: value of optional type 'UInt8?' not unwrapped; did you mean to use '!' or '?'?
result.append(byte)
^
!
$ swift --version
Swift version 3.0-dev (LLVM 752e1430fc, Clang 3987718dae, Swift 36739f7b57)
Target: x86_64-unknown-linux-gnu
The text was updated successfully, but these errors were encountered:
I think we don't actually allow same-scope shadowing anywhere, and then it coincidentally works with parameters and at the top-level because we're not checking it properly. It's probably worth coming up with the model for how you want it to work, and then making that happen everywhere. That may be language-related enough to go through the Swift Evolution Process.
(As an example of a tricky case, what if the name being shadowed is a var?)
Additional Detail from JIRA
md5: f9b23c669a0aecc42cc654aeb5f30753
Issue Description:
This compiles:
But when I wrap it in a while loop, it doesn't compile:
The compiler fails with this error:
The text was updated successfully, but these errors were encountered: