diff --git a/modules/internal/ChapelRange.chpl b/modules/internal/ChapelRange.chpl index fd15f5d17705..54baae4801a8 100644 --- a/modules/internal/ChapelRange.chpl +++ b/modules/internal/ChapelRange.chpl @@ -265,6 +265,24 @@ module ChapelRange { proc range.init(type idxType, param bounds: boundKind, param strides: strideKind) { + + if chpl_warnUnstable && (bounds == boundKind.low || bounds == boundKind.high) + then warning("Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable"); + + this.init(idxType, bounds, strides, + _low = chpl__defaultLowBound(idxType, bounds), + _high = chpl__defaultHighBound(idxType, bounds), + _stride = strides.defaultStride():chpl__rangeStrideType(idxType), + alignmentValue = 0:chpl__rangeStrideType(idxType)); + } + + // this overload can be removed when the unstable warning in the above overload is removed + @chpldoc.nodoc + proc range.init(type idxType, + param bounds: boundKind, + param strides: strideKind, + param internal: bool) { + this.init(idxType, bounds, strides, _low = chpl__defaultLowBound(idxType, bounds), _high = chpl__defaultHighBound(idxType, bounds), @@ -1760,7 +1778,7 @@ operator :(r: range(?), type t: range(?)) where chpl_castIsSafe(r, t) { checkBounds(t, r); checkEnumIdx(t, r); - var tmp: t; + var tmp = new range(t.idxType, t.bounds, t.strides, true); type srcType = r.idxType, dstType = t.idxType, dstIntType = tmp.chpl_integralIdxType; @@ -1792,7 +1810,7 @@ operator :(r: range(?), type t: range(?)) throws where !chpl_castIsSafe(r, t) { checkBounds(t, r); checkEnumIdx(t, r); - var tmp: t; + var tmp = new range(t.idxType, t.bounds, t.strides, true); type srcType = r.idxType, dstType = t.idxType, dstIntType = tmp.chpl_integralIdxType; diff --git a/test/unstable/defaultUnboundedRange.chpl b/test/unstable/defaultUnboundedRange.chpl new file mode 100644 index 000000000000..0a1ecdd947b5 --- /dev/null +++ b/test/unstable/defaultUnboundedRange.chpl @@ -0,0 +1,15 @@ + +// only low and high default initialization should be unstable +var drlb: range(int, boundKind.low), + drub: range(int, boundKind.high), + drnb: range(int, boundKind.neither), + drbb: range(int, boundKind.both); + +// none of these should produce an unstable warning +var rlb = 1.., + rub = ..0, + rnb = .., + rbb = 1..0; + +writeln(drlb); +writeln(drub); diff --git a/test/unstable/defaultUnboundedRange.good b/test/unstable/defaultUnboundedRange.good new file mode 100644 index 000000000000..d79526cdcede --- /dev/null +++ b/test/unstable/defaultUnboundedRange.good @@ -0,0 +1,4 @@ +1.. +..0 +defaultUnboundedRange.chpl:3: warning: Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable +defaultUnboundedRange.chpl:4: warning: Default initialization of a range with 'boundKind.low' or 'boundKind.high' is unstable