This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: minor problem and workaround with for


Anthony Tomasic wrote:
{--1--} for $x in (1 to 3) return ($x,$x)
1 1 2 2 3 3
{--2--} for $x in (1 to 3) return $x, $x
<stdin>:2:1: internal error while compiling - caught: java.lang.NullPointerException
Actually, according to the spec:
    for $x in (1 to 3) return $x, $x
is supposed to parse as:
    (for $x in (1 to 3) return $x), $x
which of course has an unbound variable reference.

The attached fixes the compiler failure.  We now get:

{--1--} let $y := 10 return (for $x in (1 to 3) return $x, $y)
1 2 3 10
{--2--} for $x in (1 to 3) return $x, $x
gnu.mapping.UnboundSymbol: Unbound symbol x
	at gnu.mapping.Constraint.get(Constraint.java:15)
	at gnu.mapping.Binding.get(Binding.java:25)
	at atInteractiveLevel.apply(Unknown Source)
	at gnu.mapping.CallContext.runUntilDone(CallContext.java:239)
	at gnu.expr.ModuleExp.evalModule(ModuleExp.java:189)
	at kawa.Shell.run(Shell.java:231)
	at kawa.Shell.run(Shell.java:180)
	at kawa.Shell.run(Shell.java:167)
	at kawa.Shell.run(Shell.java:154)
	at kawa.repl.main(repl.java:600)
 1 2 3

It would be nice to improve this so we get line- and column-numbers
in the exception message, but that is a fix for another day.
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/
Index: XQParser.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/xquery/lang/XQParser.java,v
retrieving revision 1.27
diff -u -r1.27 XQParser.java
--- XQParser.java	10 Jun 2002 22:31:19 -0000	1.27
+++ XQParser.java	26 Jun 2002 19:03:13 -0000
@@ -1700,7 +1700,7 @@
 	decl.noteValue (null);  // Does not have a known value.
 	decl.setFlag(Declaration.IS_SINGLE_VALUE);
       }
-    parser.push(sc); // FIXME where is matching pop?
+    parser.push(sc);
     Expression body;
     if (curToken == ',')
       {
@@ -1741,6 +1741,7 @@
 	body.setFile(getName());
 	body.setLine(bodyLine, bodyColumn);
       }
+    parser.pop(sc);
     if (isFor)
       {
 	((LambdaExp) sc).body = body;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]