# Singleton: bogus warning with optimise on

**URL:** <https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219>\
**Category:** General\
**Created:** [February 13, 2023, 7:55pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219 "2023-02-13T19:55:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [February 13, 2023, 7:55pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219/1 "2023-02-13T19:55:26Z")

</div>

```prolog
:- set_prolog_flag(optimise,true).
ss:-
   forall( (between(0,3,N), Y is N*3),
            assertion(Y is N*3)
         ).

```

```prolog
?- make.
Warning: /tmp/t1.pl:2:
Warning: Singleton variable in \+: Y
% /tmp/t1 compiled 0.00 sec, -1 clauses
true.

```

If you comment out the optimise on line the warning dissappears.

```prolog
?- make.
% /tmp/t1 compiled 0.00 sec, 0 clauses

```

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 13, 2023, 8:15pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219/2 "2023-02-13T20:15:35Z")

</div>

> [@swi](#):
>
> If you comment out the optimise on line the warning dissappears.
> 
> ```prolog
> 
> ```

Optimisation turns assertion/1 into a no-op, which is why there’s a singleton warning - the assertion check has disappeared and the code has become equivalent to `forall((between(0,3,N), Y is N*3), true)`.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [February 13, 2023, 8:16pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219/3 "2023-02-13T20:16:51Z")

</div>

ahhh…thanks. Hmm…this makes many plunit tests useless when optimization is turned on…

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 13, 2023, 8:32pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219/4 "2023-02-13T20:32:26Z")

</div>

> [@swi](#):
>
> this makes many plunit tests useless when optimization is turned on

The documentation for assertion/1 (and some other predicates) in `library(debug)` needs to be improved to point out that optimisation turns them off – it is documented in the overview section of the [documentation](https://www.swi-prolog.org/pldoc/man?section=debug). You can control this behavior with Prolog flag `optimise_debug`.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 13, 2023, 8:33pm UTC](https://swi-prolog.discourse.group/t/singleton-bogus-warning-with-optimise-on/6219/5 "2023-02-13T20:33:49Z")

</div>

You can use

```
:- set_prolog_flag(optimise_debug, false).

```

to stop optimizing debug/3 and assertion, even in debug mode. In this case it is about the intended semantics, so the warning is ok. If it is correct to optimize the assertion/1 away (or debug/3), you can use the variable \_0Name, as `_<Digit>*` variables are never subject to singleton or “multiton” messages.
