Assertion failed: ref->read->references. Possible bug?

The following program raises a failed assertion in the last SWI-Prolog stable version (and several older ones), but do not in version 7.6.4:

% Run: swipl -q -s swi_stream_assertion_reproducer.pl
% This program opens its own source for reading.
% Observed on Windows 10 and 11: SWI-Prolog 10.0.2 and 9.2.9 abort with
% "Assertion failed: ref->read->references" in src/os/pl-file.c.
% SWI-Prolog 7.6.4 completes and prints "done".

:- initialization(main, main).
main :-
    source_file(main, File),
    forall(between(1, 20, N),
           ( format(user_error, 'iteration \~d\~n', \[N\]),
             open(File, read, Input),
             set_input(Input),
             seen,
             stream_property(Stream, alias(user_input)),
             (stream_property(Stream, file_name(\_)) -> true ; true)
           )),
    writeln(done).

This is a minimal program that reproduces (thanks to GPT Terra 6.1) what happens in DES, which is why it still relies on that old SWI-Prolog version.

Thanks. Fixed.

Many thanks! Is this fix in the just published version 10.1.21? I get:

swipl -q -s swi_stream_assertion_reproducer.pl
iteration 1
iteration 2
iteration 3
Assertion failed: ref.read->references, file /home/swipl/src/swipl-devel/src/os/pl-file.c, line 1038

Now the assertion failure points to another line.