Skip to content

Commit 45e09a0

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 6423a99 commit 45e09a0

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

cmd/cli.pony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ primitive CLI
88
: (Command | (U8, String))
99
=>
1010
try
11-
match CommandParser(_spec(default_prefix)?).parse(args, envs)
11+
match \exhaustive\ CommandParser(_spec(default_prefix)?).parse(args, envs)
1212
| let c: Command => c
1313
| let h: CommandHelp => (0, h.help_string())
1414
| let e: SyntaxError => (1, e.string())

cmd/cloudsmith.pony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ primitive Cloudsmith
1111

1212
fun repo_url(repo': String): String =>
1313
let repo_name =
14-
match consume repo'
14+
match \exhaustive\ consume repo'
1515
| "nightly" => "nightlies"
1616
| "release" => "releases"
1717
| let s: String => s

cmd/http_handlers.pony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class QueryHandler is HTTPHandler
5050
end
5151

5252
fun ref chunk(data: (String | Array[U8] val)) =>
53-
match data
53+
match \exhaustive\ data
5454
| let s: String => _buf.append(s)
5555
| let bs: Array[U8] val => _buf.append(String.from_array(bs))
5656
end

cmd/main.pony

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ actor Main is PonyupNotify
2626
let default_prefix: String val =
2727
_default_root.substring(0, -"/ponyup".size().isize())
2828
let command =
29-
match recover val CLI.parse(_env.args, _env.vars, default_prefix) end
29+
match \exhaustive\ recover val CLI.parse(_env.args, _env.vars, default_prefix) end
3030
| let c: Command val => c
3131
| (let exit_code: U8, let msg: String) =>
3232
if exit_code == 0 then
@@ -180,7 +180,7 @@ actor Main is PonyupNotify
180180
end
181181

182182
be log(level: LogLevel, msg: String) =>
183-
match level
183+
match \exhaustive\ level
184184
| Info | Extra =>
185185
if (level is Info) or _verbose then
186186
if level is Extra then

cmd/packages.pony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ primitive Packages
131131
if Platform.linux() then distro end
132132

133133
fun platform_requires_distro(os: OS): Bool =>
134-
match os
134+
match \exhaustive\ os
135135
| Linux => true
136136
| Darwin => false
137137
| Windows => false

test/main.pony

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class _TestParsePlatform is UnitTest
4848
]
4949
for (input, expected) in tests.values() do
5050
h.log("input: " + input)
51-
match expected
51+
match \exhaustive\ expected
5252
| (let cpu: CPU, let os: OS, let distro: Distro) =>
5353
let pkg = Packages.from_string(input)?
5454
h.log(" => " + pkg.platform().string())

0 commit comments

Comments
 (0)