Mercury Bugs - mercury | |||||
View Issue Details | |||||
ID | Project | Category | View Status | Date Submitted | Last Update |
0000015 | mercury | Bug | public | 2007-10-05 13:25 | 2009-12-11 06:46 |
Reporter | pjrm | ||||
---|---|---|---|---|---|
Assigned To | juliensf | ||||
Priority | normal | Severity | major | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | OS | OS Version | |||
Product Version | |||||
Target Version | Fixed in Version | ||||
Summary | 0000015: wrong variable scoping in `if ( some[X] p(X) ) then q(X) ...' | ||||
Description | :- module ifsome. :- interface. :- import_module io. :- pred main(io::di, io::uo) is det. :- implementation. :- import_module string. main(!IO):- X = "outer", ( if ( some[X] X = "inner" ) then io.write_string(X, !IO), io.nl(!IO) else true ). This prints "inner", but one would expect it to print "outer" (both from one's expectations from standard predicate logic notation and from the point of view of the Mercury reference manual: "some Vars Goal ... The variables in Vars are local to the goal Goal", and the definition of if-then-else says nothing to contradict that: its statement about the declarative semantics of if-then-else is false for this example, or at least (if we want an example that still compiles after the transformation) for similar examples not involving I/O in the then/else goals). Fixing this bug is made harder by the fact that an example program in mercury_faq.texi depends on this behaviour (at least in absence of parens around the `some' goal): search for `if some'. In the example I've given, the severity of the bug is reduced by the fact that we get an `unused variable' warning (or a `shadowed variable' warning if we add another use of X). However, it is possible to construct examples that don't produce warnings by not having X outside of the if-then-else but where the behaviour differs according to whether X is bound or free on entry to the `then' goal (e.g. if the if-then-else is in semidet context and the `then' goal is `generate(X), test(X)'; and a similar generate(X),test(X) construct in the condition to avoid appears-only-once warning/objection). (I can send a 40-line example if that's useful, it's just not as succinct as the above.) This bug doesn't arise all that often, but is nevertheless a "psychologically" important bug, in that it results in a program that gives a wrong result rather than abort; it attacks Mercury's claim to logical consistency and ease of reasoning about program behaviour. pjrm. | ||||
Additional Information | I haven't checked a current ROTD. | ||||
Tags | No tags attached. | ||||
Relationships | |||||
Attached Files |
Notes | |||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
Issue History | |||||
Date Modified | Username | Field | Change | ||
---|---|---|---|---|---|
2007-10-05 13:25 | pjrm | New Issue | |||
2007-10-12 17:44 | anonymous | Note Added: 0000013 | |||
2007-10-12 18:39 | anonymous | Note Deleted: 0000013 | |||
2007-10-13 18:09 | anonymous | Note Added: 0000019 | |||
2007-10-13 18:50 | anonymous | Note Deleted: 0000019 | |||
2007-10-13 22:52 | anonymous | Note Added: 0000021 | |||
2007-10-13 22:52 | anonymous | Note Added: 0000022 | |||
2007-10-14 03:12 | anonymous | Note Added: 0000023 | |||
2007-10-14 06:56 | anonymous | Note Added: 0000024 | |||
2007-10-14 10:26 | anonymous | Note Deleted: 0000021 | |||
2007-10-14 10:27 | anonymous | Note Deleted: 0000024 | |||
2007-10-14 10:27 | anonymous | Note Deleted: 0000022 | |||
2007-10-14 10:28 | anonymous | Note Deleted: 0000023 | |||
2007-10-14 10:35 | anonymous | Note Added: 0000025 | |||
2007-10-14 10:50 | anonymous | Note Deleted: 0000025 | |||
2009-11-28 02:23 | pjrm | Note Added: 0000219 | |||
2009-12-02 20:57 | wangp | Note Added: 0000224 | |||
2009-12-02 21:08 | pbone | Note Added: 0000225 | |||
2009-12-02 22:36 | wangp | Note Added: 0000226 | |||
2009-12-04 00:30 | juliensf | Note Added: 0000228 | |||
2009-12-04 00:35 | juliensf | Note Added: 0000229 | |||
2009-12-04 02:33 | juliensf | Note Edited: 0000229 | |||
2009-12-04 09:26 | pbone | Note Added: 0000230 | |||
2009-12-11 06:45 | juliensf | Note Added: 0000233 | |||
2009-12-11 06:45 | juliensf | Status | new => resolved | ||
2009-12-11 06:45 | juliensf | Resolution | open => fixed | ||
2009-12-11 06:45 | juliensf | Assigned To | => juliensf |