快速编译多个开关案例失败情况,并且相同的命名关联值不稳定并且经常崩溃

时间:2019-01-23 13:23:35

标签: swift

Swift编译器经常因多个(> = 2)切换条件失败和相同的命名关联值而崩溃。以下代码无法针对Swift 4.2版本进行编译:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]


RewriteCond %{REQUEST_URI}  !\.(php?|jpg|gif|png|css|js|html|json|xml|eot|svg|ttf|woff|woff2|zip|csv|xlsx|webp|txt|gz|rar)$
RewriteRule ^(.*)([^/])$ https://%{HTTP_HOST}/$1$2/ [L,R=301]

在以下位置提交的错误报告:https://bugs.swift.org/browse/SR-9729

2 个答案:

答案 0 :(得分:2)

我不确定Swift是否允许fallthrough进行值绑定。

但这肯定有效:

func bar(v: Foo) {
    switch v {
    case .a(let count),
         .b(let count),
         .c(let count):
        print(count)
    case .d: break
    }
}

答案 1 :(得分:-1)

解决方法:

enum Foo {
    case a(count: Int)
    case b(count: Int)
    case c(count: Int)
    case d

    var count: Int {
        if case .a(let count) = self {
            return count
        } else if case .b(let count) = self {
            return count
        } else if case .c(let count) = self {
            return count
        } else {
            fatalError()
        }
    }
}

func bar(v: Foo) {
    switch v {
    case .a: fallthrough
    case .b: fallthrough
    case .c:
        print(v.count)
    case .d: break
    }
}

bar(v: .a(count: 4))