Mercury Bugs - mercury
View Issue Details
0000477mercuryFeature Requestpublic2019-04-17 16:512019-04-20 14:58
Reporterjuliensf 
Assigned Tozs 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000477: Infinite recursion through exception handlers
DescriptionCode such as the following is may be worth a warning.

:- pred reconstruct_route(logger::in, jscenario::in, jsolution::out)
    is cc_multi.

reconstruct_route(Log, JScenario, JSolution) :-
    ( try []
        reconstruct_route(Log, JScenario, JSolution0)
    then
        JSolution = JSolution0
    catch_any Excp ->
        trace [io(!IO)] (
            Msg = "Exception during route reconstruction: " ++ string(Excp),
            slf4j.error(Log, Msg, !IO)
        ),
        JSolution = null_jsolution
    ).
TagsNo tags attached.
Attached Files? bug477.m (871) 2019-04-18 00:37
https://bugs.mercurylang.org/file_download.php?file_id=287&type=bug

Notes
(0001023)
zs   
2019-04-17 22:28   
Can you please add a full test case?
(0001029)
juliensf   
2019-04-18 00:37   
There's a cut-down version that exhibits the behaviour attached. The current check carried out by simplify for recursive calls with the same input arguments doesn't look through higher-order calls since in general it cannot. I suspect it may be worth making a special case of try/2 (and its syntax sugared form) since wrapping an exception handler around the entry point to a Mercury program that is called from a foreign language application (which is the original setting for this) is not uncommon. Nor unfortunately is forgetting to use the correct predicate name inside the try goal which is what I did :-(
(0001038)
zs   
2019-04-20 14:58   
Feature implemented 2019 April 20.

Issue History
2019-04-17 16:51juliensfNew Issue
2019-04-17 22:28zsNote Added: 0001023
2019-04-18 00:37juliensfFile Added: bug477.m
2019-04-18 00:37juliensfNote Added: 0001029
2019-04-20 08:57zsAssigned To => zs
2019-04-20 08:57zsStatusnew => assigned
2019-04-20 14:58zsStatusassigned => resolved
2019-04-20 14:58zsResolutionopen => fixed
2019-04-20 14:58zsNote Added: 0001038