Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/md/examples/grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
'_'
<id>
<lit>
<unop> <lit>
'(' <list(<pat_bin>, ',')> ')'

<pat_nullary> ::=
Expand All @@ -320,7 +321,6 @@
'#' <id>
'#' <id> <pat_nullary>
'?' <pat_un>
<unop> <lit>

<pat_bin> ::=
<pat_un>
Expand Down
14 changes: 7 additions & 7 deletions src/mo_frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,13 @@ pat_plain :
{ VarP(x) @! at $sloc }
| l=lit
{ LitP(ref l) @! at $sloc }
| op=unop l=lit
{ match op, l with
| (PosOp | NegOp), PreLit (s, (Type.(Nat | Float) as typ)) ->
let signed = match op with NegOp -> "-" ^ s | _ -> "+" ^ s in
LitP(ref (PreLit (signed, Type.(if typ = Nat then Int else typ)))) @! at $sloc
| _ -> SignP(op, ref l) @! at $sloc
}
| LPAR ps=seplist(pat_bin, COMMA) RPAR
{ (match ps with [p] -> ParP(p) | _ -> TupP(ps)) @! at $sloc }

Expand All @@ -909,13 +916,6 @@ pat_un :
{ TagP(x, p) @! at $sloc }
| QUEST p=pat_un
{ OptP(p) @! at $sloc }
| op=unop l=lit
{ match op, l with
| (PosOp | NegOp), PreLit (s, (Type.(Nat | Float) as typ)) ->
let signed = match op with NegOp -> "-" ^ s | _ -> "+" ^ s in
LitP(ref (PreLit (signed, Type.(if typ = Nat then Int else typ)))) @! at $sloc
| _ -> SignP(op, ref l) @! at $sloc
}

pat_bin :
| p=pat_un
Expand Down
2 changes: 1 addition & 1 deletion test/run/ok/pat-subtyping.tc.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pat-subtyping.mo:6.8-6.9: warning [M0146], this pattern is never matched
pat-subtyping.mo:7.8-7.12: warning [M0146], this pattern is never matched
pat-subtyping.mo:7.8-7.10: warning [M0146], this pattern is never matched
pat-subtyping.mo:10.8-10.17: warning [M0146], this pattern is never matched
pat-subtyping.mo:11.8-11.17: warning [M0146], this pattern is never matched
pat-subtyping.mo:18.8-18.25: warning [M0146], this pattern is never matched
Expand Down
2 changes: 1 addition & 1 deletion test/run/pat-subtyping.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if false {

switch (magic ()) {
case 1 {}; // redundant
case (-1) {}; // redundant
case -1 {}; // redundant
};
switch (magic ()) {
case (1 : Nat) {}; // redundant
Expand Down
8 changes: 4 additions & 4 deletions test/run/switch.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ let x1 = switch 2 {
assert (x1 == 1);

let x2 : Int = switch (-3) {
case (0) 0;
case (-1) 2;
case (-3) 1;
case (x) x;
case 0 0;
case -1 2;
case -3 1;
case x x;
};
assert (x2 == 1);

Expand Down