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
答案 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))