[latex3-commits] [l3svn] r6691 - Detect improper uses of \cs_new:Nn (fixes #69)

noreply at latex-project.org noreply at latex-project.org
Sat Aug 20 00:14:26 CEST 2016


Author: bruno
Date: 2016-08-20 00:14:26 +0200 (Sat, 20 Aug 2016)
New Revision: 6691

Modified:
   trunk/l3kernel/l3basics.dtx
   trunk/l3kernel/l3msg.dtx
   trunk/l3kernel/testfiles/m3basics002.tlg
   trunk/l3kernel/testfiles/m3expl001.luatex.tlg
   trunk/l3kernel/testfiles/m3expl001.ptex.tlg
   trunk/l3kernel/testfiles/m3expl001.tlg
   trunk/l3kernel/testfiles/m3expl001.uptex.tlg
   trunk/l3kernel/testfiles/m3expl001.xetex.tlg
   trunk/l3kernel/testfiles/m3expl003.luatex.tlg
   trunk/l3kernel/testfiles/m3expl003.ptex.tlg
   trunk/l3kernel/testfiles/m3expl003.tlg
   trunk/l3kernel/testfiles/m3expl003.uptex.tlg
   trunk/l3kernel/testfiles/m3expl003.xetex.tlg
Log:
Detect improper uses of \cs_new:Nn (fixes #69)

\cs_new:Nn and friends with :Nn, :cn, :Nx, :cx signatures
(not :Npn, :cpn, :Npx, :cpx) are only meant to define base
functions whose signature consists only of N and n arguments,
as they will not do expansion.  I've added an error message.

Actually I had to allow T and F arguments as well otherwise
contrib tests would break (mainly due to fontspec?).


Modified: trunk/l3kernel/l3basics.dtx
===================================================================
--- trunk/l3kernel/l3basics.dtx	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/l3basics.dtx	2016-08-19 22:14:26 UTC (rev 6691)
@@ -2798,6 +2798,12 @@
   {
     \bool_if:NTF #3
       {
+        \str_if_eq_x:nnF { }
+          { \tl_map_function:nN {#2} \__cs_generate_from_signature:n }
+          {
+            \__msg_kernel_error:nnx { kernel } { non-base-function }
+              { \token_to_str:N #5 }
+          }
         \cs_generate_from_arg_count:NNnn
           #5 #4 { \tl_count:n {#2} } {#6}
       }
@@ -2806,6 +2812,11 @@
           { \token_to_str:N #5 }
       }
   }
+\cs_new:Npn \__cs_generate_from_signature:n #1
+  {
+    \if:w n #1 \else: \if:w N #1 \else:
+    \if:w T #1 \else: \if:w F #1 \else: #1 \fi: \fi: \fi: \fi:
+  }
 %    \end{macrocode}
 %   Then we define the 24 variants beginning with |N|.
 %    \begin{macrocode}

Modified: trunk/l3kernel/l3msg.dtx
===================================================================
--- trunk/l3kernel/l3msg.dtx	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/l3msg.dtx	2016-08-19 22:14:26 UTC (rev 6691)
@@ -1872,6 +1872,15 @@
     of~each~type.~All~the~#1~registers~have~been~used.~
     This~run~will~be~aborted~now.
   }
+\@@_kernel_new:nnnn { kernel } { non-base-function }
+  { Function~'#1'~is~not~a~base~function }
+  {
+    \c_@@_coding_error_text_tl
+    Functions~defined~through~\iow_char:N\\cs_new:Nn~must~have~
+    a~signature~consisting~of~only~normal~arguments~'N'~and~'n'.~
+    To~define~variants~use~\iow_char:N\\cs_generate_variant:Nn~
+    and~to~define~other~functions~use~\iow_char:N\\cs_new:Npn.
+  }
 \@@_kernel_new:nnnn { kernel } { missing-colon }
   { Function~'#1'~contains~no~':'. }
   {

Modified: trunk/l3kernel/testfiles/m3basics002.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3basics002.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3basics002.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -124,6 +124,24 @@
 | arguments. TeX allows between 0 and 9 arguments for a single function.
 |...............................................
 > \foo:nnnnnnnnnn=undefined.
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/non-base-function"
+! 
+! Function '\foo:noc' is not a base function
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| Functions defined through \cs_new:Nn must have a signature consisting of
+| only normal arguments 'N' and 'n'. To define variants use
+| \cs_generate_variant:Nn and to define other functions use \cs_new:Npn.
+|...............................................
 > \foo:noc=\long macro:#1#2#3->#1#2#3.
 ============================================================
 ============================================================
@@ -345,5 +363,23 @@
 |...............................................
 Defining \bar:nn on line ...
 \protected\long macro:#1#2->#1
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/non-base-function"
+! 
+! Function '\bar:abcdefghi' is not a base function
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| Functions defined through \cs_new:Nn must have a signature consisting of
+| only normal arguments 'N' and 'n'. To define variants use
+| \cs_generate_variant:Nn and to define other functions use \cs_new:Npn.
+|...............................................
 Defining \bar:abcdefghi on line ...
 ============================================================

Modified: trunk/l3kernel/testfiles/m3expl001.luatex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.luatex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl001.luatex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -49,6 +49,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2706,6 +2707,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.ptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.ptex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl001.ptex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl001.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.uptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.uptex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl001.uptex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl001.xetex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl001.xetex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl001.xetex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2704,6 +2705,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.luatex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.luatex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl003.luatex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -49,6 +49,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2706,6 +2707,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.ptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.ptex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl003.ptex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl003.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.uptex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.uptex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl003.uptex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2697,6 +2698,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...

Modified: trunk/l3kernel/testfiles/m3expl003.xetex.tlg
===================================================================
--- trunk/l3kernel/testfiles/m3expl003.xetex.tlg	2016-08-19 21:35:23 UTC (rev 6690)
+++ trunk/l3kernel/testfiles/m3expl003.xetex.tlg	2016-08-19 22:14:26 UTC (rev 6691)
@@ -48,6 +48,7 @@
 Defining \cs_generate_from_arg_count:Ncnn on line ...
 Defining \__cs_generate_from_signature:NNn on line ...
 Defining \__cs_generate_from_signature:nnNNNn on line ...
+Defining \__cs_generate_from_signature:n on line ...
 Defining \cs_set:Nn on line ...
 Defining \cs_set:Nx on line ...
 Defining \cs_set_nopar:Nn on line ...
@@ -2704,6 +2705,7 @@
 Defining message LaTeX/kernel/command-not-defined on line ...
 Defining message LaTeX/kernel/empty-search-pattern on line ...
 Defining message LaTeX/kernel/out-of-registers on line ...
+Defining message LaTeX/kernel/non-base-function on line ...
 Defining message LaTeX/kernel/missing-colon on line ...
 Defining message LaTeX/kernel/protected-predicate on line ...
 Defining message LaTeX/kernel/conditional-form-unknown on line ...



More information about the latex3-commits mailing list