REPL prints wrong dictionary values

(Motivated by this question on Stack Overflow.) Evaluating a dictionary with boolean values results in a wrong output, where false is printed instead of true:

$ swift
Welcome to Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1). Type :help for assistance.
  1> let dict = ["foo" : true]
dict: [String : Bool] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = false
  }
}
  2> dict
$R0: [String : Bool] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = false
  }
}

print()ing the dictionary works as expected:

  3> print(dict)
["foo": true]

Is this a known issue?

1 Like

Well, that’s mighty weird. It also seem eminently bugworthy. Please file a bug, then post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Filed as SR-9697– REPL displays wrong boolean dictionary values .

I fixed this in the 5.0 timeframe. Please try top-of-tree (or a recent snapshot), and let me know if the issue is still there. Thanks!

2 Likes
Davides-Mac-Pro:bin davide$ ./lldb --repl
Welcome to Swift version 5.0-dev (LLVM f63b283c71, Clang 41ac4c4262, Swift 542d02a60e).
Type :help for assistance.
  1> let dict = ["foo" : true]
dict: [String : Bool] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = true
  }
}
  2> dict
$R0: [String : Bool] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = true
  }
}

Confirmed. Works correctly with development snapshot from January 16, 2019:

$ ./swift-DEVELOPMENT-SNAPSHOT-2019-01-16-a.xctoolchain/usr/bin/swift
Welcome to Apple Swift version 5.0-dev (LLVM f63b283c71, Clang 41ac4c4262, Swift b34f9f8392).
Type :help for assistance.
  1> let d = ["foo" : true]
d: [String : Bool] = 1 key/value pair {
  [0] = {
    key = "foo"
    value = true
  }
}