Skip to content

Commit

Permalink
bugfix: issue #4054 (treat negative float literals as static) (#4063)
Browse files Browse the repository at this point in the history
Fix for issue #4054 
Adopting the same hack we use for integral literals.
  • Loading branch information
crusso authored Jun 23, 2023
1 parent 6cbf42c commit 566defa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/mo_frontend/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ exp_un(B) :
{ OptE(e) @? at $sloc }
| op=unop e=exp_un(ob)
{ match op, e.it with
| (PosOp | NegOp), LitE {contents = PreLit (s, Type.Nat)} ->
| (PosOp | NegOp), LitE {contents = PreLit (s, (Type.(Nat | Float) as typ))} ->
let signed = match op with NegOp -> "-" ^ s | _ -> "+" ^ s in
LitE(ref (PreLit (signed, Type.Int))) @? at $sloc
LitE(ref (PreLit (signed, Type.(if typ = Nat then Int else typ)))) @? at $sloc
| _ -> UnE(ref Type.Pre, op, e) @? at $sloc
}
| op=unassign e=exp_un(ob)
Expand Down Expand Up @@ -796,9 +796,9 @@ pat_un :
{ OptP(p) @! at $sloc }
| op=unop l=lit
{ match op, l with
| (PosOp | NegOp), PreLit (s, Type.Nat) ->
| (PosOp | NegOp), PreLit (s, (Type.(Nat | Float) as typ)) ->
let signed = match op with NegOp -> "-" ^ s | _ -> "+" ^ s in
LitP(ref (PreLit (signed, Type.Int))) @! at $sloc
LitP(ref (PreLit (signed, Type.(if typ = Nat then Int else typ)))) @! at $sloc
| _ -> SignP(op, ref l) @! at $sloc
}

Expand Down
5 changes: 5 additions & 0 deletions test/run/issue-4054.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module f = {
let f1 = -1.0;
let f2 = +1.0;
let f3 = 1.0;
}

0 comments on commit 566defa

Please sign in to comment.