[ nice-Bugs-1096722 ] requires doesn't work like assert. SHould

"SourceForge.net" <[email protected]> Wed, 05 Jan 2005 15:50:56 -0800
Newsgroups gmane.comp.lang.nice.devel
Message-ID <[email protected]>
Bugs item #1096722, was opened at 2005-01-05 15:55
Message generated for change (Comment added) made by mbeckerle
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1096722&group_id=12788

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: mike.beckerle (mbeckerle)
Assigned to: Nobody/Anonymous (nobody)
Summary: requires doesn't work like assert. SHould

Initial Comment:
int foo(Object arg) requires (arg instanceof Integer)
{
  // assert(arg instanceof Integer); // redundant 
  return arg.intValue();
}

Version 0.9.10

Problem is that a requires clause which narrows the type 
should be respected to the same extent as an assertion.

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

>Comment By: mike.beckerle (mbeckerle)
Date: 2005-01-05 18:50

Message:
Logged In: YES 
user_id=1182016


I didn't provide enough code to motivate the example.

Here's my situation:

I have a list of functions

class MyFunctionList extends LinkedList<(Object -> Object)> 
{}


The actual functions are type specific, That is, some 
functions only work on Integers, others on Strings.

So, each function looks roughly like this:

Object myIntegerFunc(Object arg)
  requires (arg instanceof Integer)
{
.... code here should assume arg is an Integer....
}

Object myStringFunc(Object arg)
  requires (arg instanceof String)
{
...code here should assume arg is a string....
}

Allas, I can't use requires. I have to put asserts into the 
above. That's the bug I'm reporting.

Both the functions are put into a list

let MyFuncList myFnList = new MyFuncList([myIntegerFunc, 
myStringFunc]);

This also tells you why I'm using Integer. It's because I need 
polymorphic objects that can be String or Integer (or other 
things eventually)

This turns out to be a big pain in Nice (as it would be in Java) 
since support for non-primitive number types is so poor. btw 
I noticed that Java's new "autoboxing/unboxing" for numbers 
isn't there in Nice.






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

Comment By: Arjan Boeijink (arjanb)
Date: 2005-01-05 17:11

Message:
Logged In: YES 
user_id=688815

This is not a bug I think.
All things that are expressable in the arguments types don't 
need to be in preconditions.
Why not write:
int foo(int arg) instead?

btw Integer is the java class and should usually not be used 
in Nice code.

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

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


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt