[latex3-commits] [l3svn] r6934 - Warn when defining a new command if auxiliaries already exist

noreply at latex-project.org noreply at latex-project.org
Thu Feb 16 20:15:42 CET 2017


Author: bruno
Date: 2017-02-16 20:15:42 +0100 (Thu, 16 Feb 2017)
New Revision: 6934

Modified:
   trunk/l3packages/xparse/testfiles/xparse004.luatex.tlg
   trunk/l3packages/xparse/testfiles/xparse004.lvt
   trunk/l3packages/xparse/testfiles/xparse004.tlg
   trunk/l3packages/xparse/xparse.dtx
Log:
Warn when defining a new command if auxiliaries already exist

This catches situations where someone used \let to undefine a
command and then tried to redefine it.  But it does not catch
cases like

    \NewDocumentCommand{\foo}{}{}
    % above in package, below user code
    \let\myfoo\foo
    \RenewDocumentCommand{\foo}{}{patch \myfoo}

which lead to an infinite loop.  No idea how to catch that.


Modified: trunk/l3packages/xparse/testfiles/xparse004.luatex.tlg
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse004.luatex.tlg	2017-02-16 00:01:28 UTC (rev 6933)
+++ trunk/l3packages/xparse/testfiles/xparse004.luatex.tlg	2017-02-16 19:15:42 UTC (rev 6934)
@@ -1678,3 +1678,24 @@
 .................................................
 |b|c|
 ============================================================
+============================================================
+TEST 24: Wrongly undefining an xparse command
+============================================================
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'm' on line ....
+.................................................
+*************************************************
+* LaTeX warning: "xparse/unsupported-let"
+* 
+* The command '\foo' was undefined but not the associated commands '\foo code'
+* and/or '\foo defaults'. Maybe you tried using \let. This may lead to an
+* infinite loop.
+*************************************************
+.................................................
+. LaTeX info: "xparse/define-command"
+. 
+. Defining command \foo with sig. 'm' on line ....
+.................................................
+============================================================

Modified: trunk/l3packages/xparse/testfiles/xparse004.lvt
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse004.lvt	2017-02-16 00:01:28 UTC (rev 6933)
+++ trunk/l3packages/xparse/testfiles/xparse004.lvt	2017-02-16 19:15:42 UTC (rev 6934)
@@ -412,4 +412,11 @@
     \TYPE { \foo {b} {c} }
   }
 
+\TEST { Wrongly~undefining~an~xparse~command }
+  {
+    \DeclareDocumentCommand { \foo } { m } {#1}
+    \let\foo\relax
+    \DeclareDocumentCommand { \foo } { m } {|#1|}
+  }
+
 \END

Modified: trunk/l3packages/xparse/testfiles/xparse004.tlg
===================================================================
--- trunk/l3packages/xparse/testfiles/xparse004.tlg	2017-02-16 00:01:28 UTC (rev 6933)
+++ trunk/l3packages/xparse/testfiles/xparse004.tlg	2017-02-16 19:15:42 UTC (rev 6934)
@@ -1678,3 +1678,24 @@
 .................................................
 |b|c|
 ============================================================
+============================================================
+TEST 24: Wrongly undefining an xparse command
+============================================================
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'm' on line ....
+.................................................
+*************************************************
+* LaTeX warning: "xparse/unsupported-let"
+* 
+* The command '\foo' was undefined but not the associated commands '\foo code'
+* and/or '\foo defaults'. Maybe you tried using \let. This may lead to an
+* infinite loop.
+*************************************************
+.................................................
+. LaTeX info: "xparse/define-command"
+. 
+. Defining command \foo with sig. 'm' on line ....
+.................................................
+============================================================

Modified: trunk/l3packages/xparse/xparse.dtx
===================================================================
--- trunk/l3packages/xparse/xparse.dtx	2017-02-16 00:01:28 UTC (rev 6933)
+++ trunk/l3packages/xparse/xparse.dtx	2017-02-16 19:15:42 UTC (rev 6934)
@@ -1048,6 +1048,13 @@
           { \token_to_str:N #1 } { \tl_to_str:n {#2} }
       }
       {
+        \bool_lazy_or:nnT
+          { \cs_if_exist_p:c { \cs_to_str:N #1 ~ code } }
+          { \cs_if_exist_p:c { \cs_to_str:N #1 ~ defaults } }
+          {
+            \__msg_kernel_warning:nnx { xparse } { unsupported-let }
+              { \token_to_str:N #1 }
+          }
         \__msg_kernel_info:nnxx { xparse } { define-command }
           { \token_to_str:N #1 } { \tl_to_str:n {#2} }
       }
@@ -4231,6 +4238,12 @@
     as~a~previous~optional~argument,~it~will~not~be~possible~to~
     omit~all~optional~arguments~when~calling~this~command.
   }
+\__msg_kernel_new:nnn { xparse } { unsupported-let }
+  {
+    The~command~'#1'~was~undefined~but~not~the~associated~commands~
+    '#1~code'~and/or~'#1~defaults'.~Maybe~you~tried~using~
+    \iow_char:N\\let.~This~may~lead~to~an~infinite~loop.
+  }
 %    \end{macrocode}
 %
 % \subsection{User functions}



More information about the latex3-commits mailing list