[m-users.] Compiler bug found

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Feb 24 02:15:45 AEDT 2023


2023-02-24 02:08 GMT+11:00 "Volker Wysk" <post at volker-wysk.de>:
> Hi!
> 
> I get a compiler error with this piece of code:
> 
> 
> :- pred main1(io::di, io::uo) is det.
> 
> main1(!IO) :-
>     io.write_string("Parent\n", !IO),
>     spawn_ex(yes, "echo", ["Hallo", "Welt"], _Pid, !IO),
>     spawn_ex(no, "echo", ["Hallo", "Welt"], _Pid, !IO).
> 
> 
> The error message is:
> 
> 
> test.m:048: In `main1'(di, uo):
> test.m:048:   error: determinism declaration not satisfied.
> test.m:048:   Declared `cc_multi', inferred `semidet'.
> test.m:048:   The reason for the difference is the following.
> test.m:053:   In argument 4 of call to predicate `process.spawn_ex'/6:
> test.m:053:   unification with `_Pid' can fail.
> test.m:052: In clause for predicate `main1'/2:
> test.m:052:   warning: variable `_Pid' occurs more than once in this scope.
> test.m:053: In clause for predicate `main1'/2:
> test.m:053:   warning: variable `_Pid' occurs more than once in this scope.
> 
> 
> After changing the "_Pid" variables to "_", it works.

That is not a bug. Section 2.6 of the reference manual (in the ROTD version) says:

A variable token consisting of single underscore is treated specially:
each instance of @samp{_} denotes a distinct variable.

It does NOT say that *every* variable that starts with an underscore denotes
a distinct variable. The initial underscore tells the compiler that the variable
is intended to be a singleton, and thus the compiler should not generate
a singleton variable for it, but it does not make every occurrence of the name
a separate variable, except for the one variable name "_".

Zoltan.


More information about the users mailing list