Skip to content

Commit efbbb67

Browse files
committed
Add \exhaustive\ annotation to exhaustive match blocks
Ponyc recently added an \exhaustive\ annotation for match expressions. When present, the compiler will fail compilation if the match is not exhaustive. This protects against future breakage if new variants are added to a union type.
1 parent a3c436b commit efbbb67

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎appdirs/_test.pony‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ primitive \nodoc\ _AppDirsTestUtil
5454
h: TestHelper,
5555
loc: SourceLoc = __loc) ?
5656
=>
57-
match expected.home_dir
57+
match \exhaustive\ expected.home_dir
5858
| _ExpectError =>
5959
h.assert_error(
6060
{()? => app_dirs.user_home_dir()? }
@@ -65,7 +65,7 @@ primitive \nodoc\ _AppDirsTestUtil
6565
app_dirs.user_home_dir()?
6666
where loc = loc)
6767
end
68-
match expected.user_data_dir
68+
match \exhaustive\ expected.user_data_dir
6969
| _ExpectError =>
7070
h.assert_error(
7171
{()? => app_dirs.user_data_dir()? }
@@ -76,7 +76,7 @@ primitive \nodoc\ _AppDirsTestUtil
7676
app_dirs.user_data_dir()?
7777
where loc = loc)
7878
end
79-
match expected.site_data_dirs
79+
match \exhaustive\ expected.site_data_dirs
8080
| _ExpectError =>
8181
h.assert_error(
8282
{()? => app_dirs.site_data_dirs()? }
@@ -88,7 +88,7 @@ primitive \nodoc\ _AppDirsTestUtil
8888
where loc = loc)
8989
end
9090

91-
match expected.user_config_dir
91+
match \exhaustive\ expected.user_config_dir
9292
| _ExpectError =>
9393
h.assert_error(
9494
{()? => app_dirs.user_config_dir()? }
@@ -99,7 +99,7 @@ primitive \nodoc\ _AppDirsTestUtil
9999
app_dirs.user_config_dir()?
100100
where loc = loc)
101101
end
102-
match expected.site_config_dirs
102+
match \exhaustive\ expected.site_config_dirs
103103
| _ExpectError =>
104104
h.assert_error(
105105
{()? => app_dirs.site_config_dirs()? }
@@ -111,7 +111,7 @@ primitive \nodoc\ _AppDirsTestUtil
111111
where loc = loc)
112112
end
113113

114-
match expected.user_cache_dir
114+
match \exhaustive\ expected.user_cache_dir
115115
| _ExpectError =>
116116
h.assert_error(
117117
{()? => app_dirs.user_cache_dir()? }
@@ -123,7 +123,7 @@ primitive \nodoc\ _AppDirsTestUtil
123123
where loc = loc)
124124
end
125125

126-
match expected.user_state_dir
126+
match \exhaustive\ expected.user_state_dir
127127
| _ExpectError =>
128128
h.assert_error(
129129
{()? => app_dirs.user_state_dir()? }
@@ -135,7 +135,7 @@ primitive \nodoc\ _AppDirsTestUtil
135135
where loc = loc)
136136
end
137137

138-
match expected.user_log_dir
138+
match \exhaustive\ expected.user_log_dir
139139
| _ExpectError =>
140140
h.assert_error(
141141
{()? => app_dirs.user_log_dir()? }

‎appdirs/appdirs.pony‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type _Maybe[T] is (T | None)
3737

3838
primitive _Opt
3939
fun get[T](s: _Maybe[T], or_else: T): T =>
40-
match consume s
40+
match \exhaustive\ consume s
4141
| let value: T => consume value
4242
| None => consume or_else
4343
end
@@ -126,7 +126,7 @@ class AppDirs
126126
dir for this application.
127127
"""
128128
let os_specific_dir =
129-
match _platform
129+
match \exhaustive\ _platform
130130
| _Osx =>
131131
Paths.join(
132132
[ _home as String
@@ -153,7 +153,7 @@ class AppDirs
153153
""
154154
end
155155
end
156-
match _app_version
156+
match \exhaustive\ _app_version
157157
| None => os_specific_dir
158158
| let v: String => Path.join(os_specific_dir, v)
159159
end
@@ -175,7 +175,7 @@ class AppDirs
175175
data dirs for this application.
176176
"""
177177
let os_specific_dirs: Array[String] iso =
178-
match _platform
178+
match \exhaustive\ _platform
179179
| _Osx =>
180180
recover
181181
[ Path.join(
@@ -239,7 +239,7 @@ class AppDirs
239239
for this application.
240240
"""
241241
let os_specific_dir =
242-
match _platform
242+
match \exhaustive\ _platform
243243
| _Osx =>
244244
Paths.join(
245245
[ _home as String
@@ -254,7 +254,7 @@ class AppDirs
254254
end
255255

256256
// apply version
257-
match _app_version
257+
match \exhaustive\ _app_version
258258
| None => os_specific_dir
259259
| let v: String =>
260260
Path.join(os_specific_dir, v)
@@ -275,7 +275,7 @@ class AppDirs
275275
for this application.
276276
"""
277277
let os_specific_dirs: Array[String] iso =
278-
match _platform
278+
match \exhaustive\ _platform
279279
| _Osx =>
280280
recover
281281
[ Path.join(
@@ -326,7 +326,7 @@ class AppDirs
326326
for this application.
327327
"""
328328
let os_specific_dir =
329-
match _platform
329+
match \exhaustive\ _platform
330330
| _Osx =>
331331
Paths.join(
332332
[ _home as String
@@ -351,7 +351,7 @@ class AppDirs
351351
""
352352
end
353353
end
354-
match _app_version
354+
match \exhaustive\ _app_version
355355
| None => os_specific_dir
356356
| let v: String => Path.join(os_specific_dir, v)
357357
end
@@ -371,7 +371,7 @@ class AppDirs
371371
See:
372372
https://wiki.debian.org/XDGBaseDirectorySpecification#state
373373
"""
374-
match _platform
374+
match \exhaustive\ _platform
375375
| _Osx | _Windows =>
376376
user_data_dir()?
377377
| _OsxAsUnix | _Unix =>
@@ -393,7 +393,7 @@ class AppDirs
393393
Return full path to the user-specific log dir
394394
for this application.
395395
"""
396-
match _platform
396+
match \exhaustive\ _platform
397397
| _Osx =>
398398
Paths.join(
399399
[ _home as String

0 commit comments

Comments
 (0)