Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\cctab_const:Nn raises "Inconsistent local/global assignment" errors #1508

Closed
muzimuzhi opened this issue Mar 19, 2024 · 1 comment · Fixed by #1509
Closed

\cctab_const:Nn raises "Inconsistent local/global assignment" errors #1508

muzimuzhi opened this issue Mar 19, 2024 · 1 comment · Fixed by #1509

Comments

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Mar 19, 2024

\documentclass{article}

\ExplSyntaxOn
\debug_on:n { check-declarations }

\cctab_const:Nn \c_my_cctab {}
\ExplSyntaxOff

\begin{document}
\end{document}

Compiled with non-LuaLaTeX, this raises three "Inconsistent local/global assignment" errors.

  • First error is raised by \cctab_new:N \c_..._cctab used by \cctab_const:Nn
  • Second one is raised by \intarray_new:N \c_..._cctab used by \__cctab_new:N, which is used by \cctab_new:N
  • Third one is raised by \cctab_gset:N \c_..._cctab used by \cctab_const:Nn

With LuaLaTeX, only the first and last are raised because \__cctab_new:n is based on \newcatcodetable not intarray.

! LaTeX Error: Inconsistent local/global assignment

For immediate help type H <return>.
 ...                                              
                                                  
l.6 \cctab_const:Nn \c_my_cctab {}
                                  

This is a coding error.

Global assignment to a constant variable '\c_my_cctab'.

latex3/l3kernel/l3cctab.dtx

Lines 802 to 806 in 35b15d8

\cs_new_protected:Npn \cctab_const:Nn #1#2
{
\cctab_new:N #1
\cctab_gset:Nn #1 {#2}
}

latex3/l3kernel/l3cctab.dtx

Lines 294 to 315 in 35b15d8

\cs_new_protected:Npn \@@_new:N #1
{ \intarray_new:Nn #1 { 257 } }
\cs_new_protected:Npn \@@_gstore:Nnn #1#2#3
{ \intarray_gset:Nnn #1 { \int_eval:n { #2 + 1 } } {#3} }
\cs_new_protected:Npn \cctab_new:N #1
{
\__kernel_chk_if_free_cs:N #1
\@@_new:N #1
\int_step_inline:nn { 256 }
{ \__kernel_intarray_gset:Nnn #1 {##1} { 12 } }
\__kernel_intarray_gset:Nnn #1 { 257 } { 13 }
\@@_gstore:Nnn #1 { 0 } { 9 }
\@@_gstore:Nnn #1 { 13 } { 5 }
\@@_gstore:Nnn #1 { 32 } { 10 }
\@@_gstore:Nnn #1 { 37 } { 14 }
\int_step_inline:nnn { 65 } { 90 }
{ \@@_gstore:Nnn #1 {##1} { 11 } }
\@@_gstore:Nnn #1 { 92 } { 0 }
\int_step_inline:nnn { 97 } { 122 }
{ \@@_gstore:Nnn #1 {##1} { 11 } }
\@@_gstore:Nnn #1 { 127 } { 15 }
}

The first and third errors can be avoided by rewriting \cctab_const:Nn in implementations of \cctab_new:N and \cctab_gset:Nn, for example

\documentclass{article}

\ExplSyntaxOn
\cs_undefine:N \cctab_const:Nn
\cs_new_protected:Npn \cctab_const:Nn #1#2
  {
    \__kernel_chk_if_free_cs:N #1
    \__cctab_new:N #1
    \group_begin:
      \cctab_select:N \c_initex_cctab
      #2 \scan_stop:
      \__cctab_gset:n {#1}
    \group_end:
  }

\debug_on:n { check-declarations }

\cctab_const:Nn \c_my_cctab {}
\ExplSyntaxOff

\begin{document}
\end{document}

but to avoid the second error it seems \intarray_const:Nnn <intarray var> {<size>} { <position-value pairs> } is needed.

@muzimuzhi
Copy link
Contributor Author

muzimuzhi commented Mar 19, 2024

but to avoid the second error it seems \intarray_const:Nnn <intarray var> {<size>} { <position-value pairs> } is needed.

Or we can wrap relevant lines in between \debug_suspend: and \debug_resume:, like how \coffin_new:N does.

% \begin{macro}{\coffin_new:N, \coffin_new:c}
% Creating a new coffin means making the underlying box and adding the
% data structures. The \cs{debug_suspend:} and \cs{debug_resume:} functions
% prevent \cs{prop_gclear_new:c} from writing useless information to
% the log file.
% \begin{macrocode}
\cs_new_protected:Npn \coffin_new:N #1
{
\box_new:N #1
\debug_suspend:
\prop_gclear_new:c { coffin ~ \@@_to_value:N #1 ~ corners }
\prop_gclear_new:c { coffin ~ \@@_to_value:N #1 ~ poles }
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ corners }
\c_@@_corners_prop
\prop_gset_eq:cN { coffin ~ \@@_to_value:N #1 ~ poles }
\c_@@_poles_prop
\debug_resume:
}

muzimuzhi added a commit to muzimuzhi/latex3 that referenced this issue Apr 2, 2024
This also avoids duplicate inconsistent local/global assignment errors raised
by \cctab_new:N and unwanted logging written by \cctab_begin: in non-LuaTeX
engines.

See latex3#1508.
josephwright pushed a commit that referenced this issue Apr 2, 2024
This also avoids duplicate inconsistent local/global assignment errors raised
by \cctab_new:N and unwanted logging written by \cctab_begin: in non-LuaTeX
engines.

See #1508.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant