Index: gnu/expr/ChangeLog =================================================================== --- gnu/expr/ChangeLog (revision 7584) +++ gnu/expr/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2013-09-11 Matthieu Vachon + + * FindCapturedVars.java (visitReferenceExp): Added a check + to see if unknown declaration will be bound at runtime + which is the case for command-line-arguments when a main + method needs to be generated. + 2013-09-07 Per Bothner * PrimProcedure.java (mostSpecific): Moved from MethodProc. Index: gnu/expr/FindCapturedVars.java =================================================================== --- gnu/expr/FindCapturedVars.java (revision 7584) +++ gnu/expr/FindCapturedVars.java (working copy) @@ -476,9 +476,10 @@ public class FindCapturedVars extends ExpExpVisitor exp.isProcedureName()); exp.setBinding(decl); } - if (decl.getFlag(Declaration.IS_UNKNOWN)) + if (decl.getFlag(Declaration.IS_UNKNOWN) && !isBoundAtRuntime(decl, comp)) { maybeWarnNoDeclarationSeen(exp.getSymbol(), exp.isProcedureName(), comp, exp); + } capture(exp.contextDecl(), decl); return exp; @@ -540,4 +541,20 @@ public class FindCapturedVars extends ExpExpVisitor return super.visitSetExp(exp, ignored); } + /** + * Returns a boolean determining if a declaration is to be bound + * into the environment at runtime only. This is the case for the + * special command-line-arguments symbol which is bound to arguments + * only at runtime. + * + * @param declaration The declaration to check for runtime injection. + * @param compilation The compilation unit associated to the declaration. + * + * @return true if declaration will be bound at runtime, false otherwise. + */ + boolean isBoundAtRuntime(Declaration declaration, Compilation compilation) + { + return compilation.generateMainMethod() && + "command-line-arguments".equals(declaration.getName()); + } } Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 7584) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,13 @@ +2013-09-13 Matthieu Vachon + + * unknown1.scm: New test to check that no warning + is issued when generating a main method and using + command-line-arguments. + + * unknown2.scm: New test to check that a warning + is issued when not generating a main method and using + command-line-arguments. + 2013-09-10 Matthieu Vachon Per Bothner Index: testsuite/unknown1.scm =================================================================== --- testsuite/unknown1.scm (revision 0) +++ testsuite/unknown1.scm (working copy) @@ -0,0 +1,5 @@ +(module-compile-options main: #t) + +;; No warning should be generated +(format #t "Argument count: ~a~%" (vector-length command-line-arguments)) +;; Output: Argument count: 0 Index: testsuite/unknown2.scm =================================================================== --- testsuite/unknown2.scm (revision 0) +++ testsuite/unknown2.scm (working copy) @@ -0,0 +1,3 @@ +;; No main method, a warning should be issued +(vector-length command-line-arguments) +;; Diagnostic: unknown2.scm:2:16: warning - no declaration seen for command-line-arguments