[ nice-Bugs-1153768 ] Compiler/parser exception when parsing option tuple

"SourceForge.net" <[email protected]> Mon, 28 Feb 2005 12:50:53 -0800
Newsgroups gmane.comp.lang.nice.devel
Message-ID <[email protected]>
Bugs item #1153768, was opened at 2005-02-28 21:36
Message generated for change (Comment added) made by bonniot
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1153768&group_id=12788

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Steve Yegge (steve_yegge)
Assigned to: Nobody/Anonymous (nobody)
Summary: Compiler/parser exception when parsing option tuple

Initial Comment:
nicec --version
Nice compiler version 0.9.10 (build 2005.02.25,
16:35:29 UTC)
Compiled using JDK 1.4.2_04

If I attempt to compile this code:

let java.util.Map<int, (int, int)> mymap = new
java.util.HashMap();

void main(String[] args) {
  mymap.put(2, (3, 4));
  (int x, int y) = mymap.get(2);
}

The compiler says:

nicec --sourcepath=.. -a hello.jar hello
nice.lang: parsing
hello: parsing
hello: typechecking

C:\java\com\stevey\soko\nice\hello\main.nice: line 5,
column 3:
The value mymap.get(2) cannot be assigned to (x, y)
because it might be null.

To allow (x, y) to contain the null value, it should be
declared as:
?(nice.lang.int, nice.lang.int) (x, y)
compilation failed with 1 error

If I then prefix the assignment like so:

?(nice.lang.int x, nice.lang.int y) = mymap.get(2);

The parser errors out with:

nicec --sourcepath=.. -a hello.jar hello
nice.lang: parsing
hello: parsing

An exception has occured in the compiler
Please fill-in a bug report at the following webpage:
http://sourceforge.net/tracker/?func=add&group_id=12788&atid=112788

Stack trace:
Exception in thread "main"
bossa.parser.Parser$LookaheadSuccess
	at bossa.parser.Parser.<init>(Parser.java:8321)
	at bossa.parser.JavaccParser.read(JavaccParser.java:67)
	at bossa.modules.Content.read(Content.java:111)
	at bossa.modules.Content.getDefinitions(Content.java:86)
	at bossa.modules.Package.read(Package.java:122)
	at bossa.modules.Package.<init>(Package.java:88)
	at bossa.modules.Package.make(Package.java:59)
	at bossa.modules.fun.setMainPackage(Compilation.nice:89)
	at
bossa.modules.Compilation.setMainPackage(Compilation.nice)
	at nice.tools.compiler.fun.compile(interface.nice:37)
	at bossa.modules.Compilation.compile(Compilation.nice)
	at nice.tools.compiler.console.fun.compile(main.nice:165)
	at
nice.tools.compiler.console.dispatch.compile(Unknown
Source)
	at nice.tools.compiler.console.fun.main(main.nice:199)
	at nice.tools.compiler.console.dispatch.main(Unknown
Source)

It's strictly a parse-time exception, in the sense that
you can reproduce the error with just this code:

void main(String[] args) {
  ?(int x, int y) = mymap.get(2);
}

(I'm not trying to claim that my code is correct; I'm
just following the compiler output instructions by
filing a bug.)

----------------------------------------------------------------------

>Comment By: Daniel Bonniot (bonniot)
Date: 2005-02-28 21:50

Message:
Logged In: YES 
user_id=88952

Thanks for you report. There are really two bugs here. The
second one (parser exception) is I think a duplicate of bug
1103449. According to Arjan, this is a bug in JavaCC, which
is already fixed in their CVS. Since this is failure on
incorrect code, I think it's fine to wait for their next
release.

The first bug is indeed a wrong error message from nicec.
That message is there to help people handle nullness errors.
However, it should not say this for tuples. We will need to
fix that.

A correct way to handle this situation is:

mymap.put(2, (3, 4));
?(int, int) tuple = mymap.get(2);
if (tuple != null)
  {
    (int x, int y) = tuple;
    ...
  }


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1153768&group_id=12788


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click