-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Parsing of semicolon followed by binary operator is confusing #6961
Description
Original bug ID: 6961
Reporter: elnatan
Status: acknowledged (set by @damiendoligez on 2015-08-19T15:03:44Z)
Resolution: open
Priority: normal
Severity: minor
Version: 4.02.1
Target version: later
Category: lexing and parsing
Related to: #4627 #5936 #6327 #6828 #7193
Monitored by: @gasche @diml @hcarty
Bug description
The following two definitions are parsed differently. Is there a good justification for this?
let () =
let x =
let x = 5 in
let x = x + 1 in
ignore x; x
in
Format.printf "%d\n" x (* prints 6; the second 'let' extends past the semicolon *)
;;
let () =
let x =
let x = 5 in
let x = x + 1 in
x; * x
in
Format.printf "%d\n" x (* prints 30; the second 'let' ended at the semicolon *)
;;
To make things more confusing, replacing '*' with '+' in the second example causes the parsing to be the same as the 'ignore' case: the program prints 6, with the 'let' extending past the semicolon and '+' being interpreted as a unary operator (and the 'x;' leading to 'Warning 10: this expression should have type unit.').
(This example is somewhat contrived, but something like this is rather realistic when using monadic operators instead of '*' and '+'.)