chiark / gitweb /
Warnings: Introduce new `broken-var-ref' warning
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 29 Dec 2019 14:01:22 +0000 (14:01 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 30 Dec 2019 11:35:16 +0000 (11:35 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
generate
tests/filter/Dir.mk.expected
tests/filter/Dir.sd.mk
tests/filter/stderr.expected

diff --git a/README b/README
index a44fb49..e303788 100644 (file)
--- a/README
+++ b/README
@@ -336,6 +336,11 @@ suppressed with the &:warn directive.  The warning tags are:
        by more letters.  Note that &$FOO works differently to
        raw make: it expands to $(sub_dir_FOO).
 
+    broken-var-ref
+        An attempt at variable expansion looking like $&...
+       You probably expected this to mean $(TOP_F)BAR but it
+       expands to $TOP_FBAR which make thinks means $(T)OP_FBAR.
+
     unknown-warning
        &:warn was used to try to enable a warning that this version
        of subdirmk does not understand.  (Note that an attempt to
index bae0995..5106129 100755 (executable)
--- a/generate
+++ b/generate
@@ -177,6 +177,7 @@ our @warn_ena_dfl = map { $_ => 1 } qw(
     local+global
     single-char-var
     unknown-warning
+    broken-var-ref
 );
 our %warn_ena = @warn_ena_dfl;
 
@@ -332,6 +333,10 @@ sub process_input_mk ($$$$) {
                    wrn 'single-char-var',
                    'possibly confusing unbracketed single-char $-expansion';
                }
+               elsif (m{^$esc}) {
+                   wrn 'broken-var-ref',
+                   'broken $&... expansion; you probably meant &$';
+               }
                elsif (m{^\(($esc)?([^()\$]+)\)} ||
                       m{^\{($esc)?([^{}\$]+)\}}) {
                    $note_varref->($2,!!$1);
index 7eecb23..5205a3a 100644 (file)
@@ -17,6 +17,8 @@ TOP_WARN += 3
 
 ${eval ${call  some-macro, 42, $$x, {  $(foreach something) } }}
 
+$TOP_FBAR
+
 # doctests:
 # Suffix in .
 
index 1a4eb1f..c97ee0f 100644 (file)
@@ -16,5 +16,7 @@ WARN += 3
 
 &${ some-macro, 42, $x, { &$- $(foreach something) } }
 
+$&FBAR
+
 # doctests:
 &:include &doctests.sd.mk
index fe8b3f2..76e32dd 100644 (file)
@@ -1,5 +1,6 @@
 subdirmk: warning (unknown-warning): ./Prefix.sd.mk:2: unknown warning many-requests-for-unknown-warning requested
 subdirmk: warning (single-char-var): ./Dir.sd.mk:8: possibly confusing unbracketed single-char $-expansion
+subdirmk: warning (broken-var-ref): ./Dir.sd.mk:19: broken $&... expansion; you probably meant &$
 subdirmk: warning (local+global): saw both WARN and &WARN
  saw WARN at ./Dir.sd.mk:6
  saw WARN at ./Dir.sd.mk:9