Skip to content

Parsing of semicolon followed by binary operator is confusing #6961

@vicuna

Description

@vicuna

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 '+'.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions