Skip to content

Commit b115ae5

Browse files
authored
Merge pull request #10655 from CodaFi/a-time-and-a-place
2 parents a4bbb82 + d27ed5a commit b115ae5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Sema/TypeCheckSwitchStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ namespace {
11041104
}
11051105
}
11061106

1107-
TC.diagnose(startLoc, diag::non_exhaustive_switch);
1107+
TC.diagnose(startLoc, mainDiagType);
11081108
TC.diagnose(startLoc, diag::missing_several_cases, false)
11091109
.fixItInsert(endLoc, buffer.str());
11101110
} else {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-typecheck-verify-swift -diagnostics-editor-mode
2+
3+
typealias TimeInterval = Double
4+
5+
let NSEC_PER_USEC : UInt64 = 1000
6+
let NSEC_PER_SEC : UInt64 = 1000000000
7+
8+
public enum TemporalProxy {
9+
case seconds(Int)
10+
case milliseconds(Int)
11+
case microseconds(Int)
12+
case nanoseconds(Int)
13+
@_downgrade_exhaustivity_check
14+
case never
15+
}
16+
17+
func unproxify(t : TemporalProxy) -> TimeInterval {
18+
switch t { // expected-warning {{switch must be exhaustive}}
19+
// expected-note@-1 {{do you want to add missing cases?}}
20+
case let .seconds(s):
21+
return TimeInterval(s)
22+
case let .milliseconds(ms):
23+
return TimeInterval(TimeInterval(ms) / 1000.0)
24+
case let .microseconds(us):
25+
return TimeInterval( UInt64(us) * NSEC_PER_USEC ) / TimeInterval(NSEC_PER_SEC)
26+
case let .nanoseconds(ns):
27+
return TimeInterval(ns) / TimeInterval(NSEC_PER_SEC)
28+
}
29+
}

0 commit comments

Comments
 (0)