Code that compile and run in a small isolated project is showing compile errors in a larger project

This code compile and run just fine in a small SwiftUI project:

extension Int {
    // collect digits ignoring negative sign
    var digits: [Int] {
        if self == 0 {
            return [0]
        var result = [Int]()
        var n = abs(self)
        while (n > 0) {
            result.append(n % 10)
            n = n / 10
        return result.reversed()

    static let superscriptMap: [Character] = [

    static let subscriptMap: [Character] = [

    var superscriptString: String {
        let ds = { Self.superscriptMap[$0] }
        if self >= 0 {
            return String(ds)
        } else {
            return "\u{207B}" + String(ds)

    var subscriptString: String {
        let ds = { Self.subscriptMap[$0] }
        if self >= 0 {
            return String(ds)
        } else {
            return "\u{208B}" + String(ds)

In a large SwiftUI project with many source files, do not compile:

The error messages seems to indicate the compiler is not able to tell the string literals are of type Character, it think those are String literals.

Xcode Version 13.2 beta (13C5066c), something wrong with Swift compiler or Xcode?

however big the project is you can strip its copy down (via binary dissection or otherwise) to a minimal app that still has the issue - then when nothing else blocking the view the bug magically becomes obvious, be it the compiler or the app bug. and if this is a compiler bug indeed - worth filing a bug report with that minimal stripped down sample code.

Are you sure there's nowhere in your module where you have defined your own Character type (or are importing a Character from another module)? I can reproduce your error messages under this circumstance. Try changing Character to Swift.Character to see if that helps.

1 Like

Thank you! I have a struct Character

The error messages make sense now :grinning:

Terms of Service

Privacy Policy

Cookie Policy