Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 330489 - [evaluator] Sequence{1..1} has no iterable content
Summary: [evaluator] Sequence{1..1} has no iterable content
Status: CLOSED FIXED
Alias: None
Product: OCL
Classification: Modeling
Component: Core (show other bugs)
Version: 3.0.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.0.2   Edit
Assignee: OCL Inbox CLA
QA Contact: Ed Willink CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-17 12:36 EST by Ed Willink CLA
Modified: 2012-05-29 13:23 EDT (History)
1 user (show)

See Also:
ed: review? (laurent.goubet)


Attachments
Fix for singleton range (3.02 KB, patch)
2010-11-17 12:59 EST, Ed Willink CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2010-11-17 12:36:10 EST
An attempt to iteration over Sequence{1..1} performs no iteration.
Comment 1 Ed Willink CLA 2010-11-17 12:59:15 EST
Created attachment 183324 [details]
Fix for singleton range

The problem is that on the first iteration of a singleton range hasNext does not find curr<last so it thinks it has finished.

An empty or negative range is not well-formed, so it seems sufficient to just return true for hasNext() in the starting !initialised context.
Comment 2 Laurent Goubet CLA 2010-11-18 02:45:29 EST
Ed,

Sequence{2..1} parses well into a CollectionRange, and such a range with your patch would allow for one iteration (as would Sequence{90..-50}). I think it would be better for the check to be 
"return (curr < last) || (!initialized && curr == last);" so that we _only_ allow for this one iteration when the range has its "first" and "last" literals equal.
Comment 3 Ed Willink CLA 2010-11-18 05:04:13 EST
The OCL 2.2 specification is undecided about whether Sequence{2..1} is well-formed; the CollectionRangeEval::getRange recursion never terminates to yield a verdict. We can infer that since it counts up till it reaches last, that 2 is in range and 1 is not in range but all integers greater than 2 are also in range so Sequence{2..1} = Sequence{2,3,4,5,6,7,....}.

I've raised an OMG issue suggesting that it could be more useful to define Sequence{3..1} = Sequence{3,2,1}.

We could certainly implement this for 3.1; I'm not sure about 3.0.2 though.
Comment 4 Laurent Goubet CLA 2010-11-18 05:16:42 EST
Sequence{3..1} = Sequence{3,2,1} would be the best behavior, but as you mentionned, I don't think this should be done in 3.0.2. And indeed the behavior with your patch (Sequence{3..1} iterates once, on the integer "3") doesn't seem that wrong since the specification only gives examples counting "up".

+1 for the current patch.
Comment 5 Ed Willink CLA 2010-11-19 01:33:22 EST
Committed to HEAD and maintenance for 3.1.0M4 and 3.0.2.
Comment 6 Ed Willink CLA 2012-05-29 13:23:52 EDT
Closing all bugs resolved in Indigo.