Bug 356228 - No NumericOverflowException for SmallInt
Summary: No NumericOverflowException for SmallInt
Status: REOPENED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-30 12:54 EDT by Kathy Carroll CLA
Modified: 2017-02-23 14:18 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kathy Carroll CLA 2011-08-30 12:54:52 EDT
program mini2 type BasicProgram {}
	function main()
		small, small2 int;		
		small = 2147483600;		
		try
			small2 = small + small;
			if (small2 < small)
				syslib.writeStdout("unexpected behavior");
			end
		onException (oops NumericOverflowException)
			SysLib.writeStdOut("Cool! Got overflow for SmallInt");
		onException(oops AnyException)
			SysLib.writeStdOut("Got an exception for SmallInt");
		end
	end
end
Comment 1 Kathy Carroll CLA 2011-09-13 15:43:55 EDT
BigInt has a problem with the generated code

======  EGL Code ==========
		variation string = "assigment overflow";
		try
			overflow bigInt = 9223372036854775810;
			variation += " no exception";
			syslib.writestdout("failed " + variation);
		onException(oops AnyException)
			if ( oops isa NumericOverflowException)
				syslib.writestdout("failed " + variation);
			else
				variation += " wrong exception";
				syslib.writestdout("failed " + variation);
			end
		end

===== Java code =========

long overflow = (long) 0;
overflow = EBigint.asBigint(new java.math.BigInteger( new byte[] { 0x0, (byte)0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2 } ));

===== Java error ======

The method asBigint(Short) in the type EBigint is not applicable for the arguments (BigInteger)
Comment 2 Jeff Douglas CLA 2011-09-13 17:08:57 EDT
Fixed.

However, the testcase snippit of code has an error in it. It reports "failed" in this:

            if ( oops isa NumericOverflowException)
                syslib.writestdout("failed " + variation);

when that is really where it passes.
Comment 3 Kathy Carroll CLA 2011-09-16 14:11:29 EDT
tested with build 201109161325
    bigInt success
    smallInt failes


program mini2 type BasicProgram {}
    function main()
		testBigInt();
		testSmallInt();
    end
    
    function testSmallInt()
    	variation string = "smallInt assigment overflow";
    	small, small2 int;        
        small = 2147483600;        
        try
            small2 = small + small;
            if (small2 < small)
            	variation += " no exception";
            	syslib.writestdout("failed " + variation);
            end
        onException(oops AnyException)
            if ( oops isa NumericOverflowException)
                syslib.writestdout("success " + variation);
            else
                variation += " wrong exception";
                syslib.writestdout("failed " + variation);
            end
        end
    end
    
    function testBigInt()
    	variation string = "bigInt assigment overflow";
        try
            overflow bigInt = 9223372036854775810;
            variation += " no exception";
            syslib.writestdout("failed " + variation);
        onException(oops AnyException)
            if ( oops isa NumericOverflowException)
                syslib.writestdout("success " + variation);
            else
                variation += " wrong exception";
                syslib.writestdout("failed " + variation);
            end
        end
    end
end
Comment 4 Jeff Douglas CLA 2011-09-16 15:36:53 EDT
Note to self:

This is because there has not been any logic added to expressions to invoke a runtime routine to test for overflow.

this code that was generated: small2 = (small + small);

needs to be something like this:

small2 = EInt.checkOverflow(small + small);

And that logic can test the result. 

We will need that runtime method in all numeric classes.
Comment 5 Matt Heitz CLA 2011-09-16 15:44:35 EDT
Overflow checking was deferred out of 0.7.  I don't think we should be throwing those exceptions.
Comment 6 Jeff Douglas CLA 2011-09-19 13:35:07 EDT
Kathy. We are changing the behavior for 0.70 to have NO overflow checking. This means any testcases that you have will not cause overflows. We are going to add support for this in 1.0.

I will be committing the runtime code changes soon, that turns off the checking that we did have, so don't be surprised.
Comment 7 Jing Qian CLA 2011-10-05 10:39:41 EDT
kathy, just skip these test cases with this bug number saying it's for 1.0
"bug 3566228 - EDT 1.0"
Comment 8 Matt Heitz CLA 2013-01-03 14:01:45 EST
Deferring to Future.  This won't be done in 0.8.2.