Pattern match failure should be caught at compile-time
Bug #408411 reported by
Matt Giuca
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mars |
Fix Released
|
Wishlist
|
Matt Giuca |
Bug Description
If a switch statement does not cover all possibilities (ie. have a case for each alternative of the type, or have a wildcard case), then the program should be rejected.
Currently a pattern match failure error is thrown at runtime. See the XXX in interpret.m under exec_cases.
Related branches
lp:~mgiuca/mars/switchfactor
- Matt Giuca: Approve
-
Diff: 2194 lines (+1570/-166)17 files modifieddoc/dev/index.rst (+31/-0)
doc/dev/switchfactor.rst (+795/-0)
doc/index.rst (+1/-0)
doc/ref/stmts.rst (+0/-8)
src/ast_cfg.m (+494/-72)
src/interpret.m (+46/-53)
src/ir.m (+25/-9)
src/mars.m (+1/-1)
src/marsc.m (+1/-1)
src/pretty.m (+30/-12)
test/cases/compiler/switch.mar (+109/-0)
test/cases/compiler/switchfail.mar (+0/-2)
test/cases/compiler/switchfail.mtc (+4/-8)
test/cases/compiler/switchfail2.mar (+13/-0)
test/cases/compiler/switchfail2.mtc (+5/-0)
test/cases/compiler/switchfail3.mar (+10/-0)
test/cases/compiler/switchfail3.mtc (+5/-0)
Changed in mars: | |
assignee: | nobody → Matt Giuca (mgiuca) |
importance: | Undecided → Wishlist |
status: | New → Confirmed |
Changed in mars: | |
status: | Confirmed → Triaged |
tags: | added: language |
Changed in mars: | |
status: | Triaged → In Progress |
Changed in mars: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
This is a requirement of the language spec:
"It must be statically provable that all possible values are handled by at least one case statement, or the compiler MUST reject the program. This can be proven either by having a wildcard pattern (underscore or variable), or by matching all alternatives of a user-defined data type.
The current implementation does not obey this last rule. Currently, this check is made at runtime, not compile time. If no case of a switch statement matches, the program will terminate with a runtime error, “pattern match failure”."