mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-14 23:53:47 +00:00
make the low bound the default value of ranges + ignoring views and notnil
This commit is contained in:
@@ -710,10 +710,7 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P
|
||||
else:
|
||||
result = nil
|
||||
of tyRange:
|
||||
if c.graph.config.isDefined("nimPreviewRangeDefault"):
|
||||
result = firstRange(c.config, aTypSkip)
|
||||
else:
|
||||
result = nil
|
||||
result = firstRange(c.config, aTypSkip)
|
||||
else:
|
||||
result = nil
|
||||
|
||||
|
||||
@@ -584,9 +584,11 @@ proc checkDefault(c: PContext, n: PNode; isDefault: bool): PNode =
|
||||
result = n
|
||||
c.config.internalAssert result[1].typ.kind == tyTypeDesc
|
||||
let constructed = result[1].typ.base
|
||||
if constructed.requiresInit:
|
||||
# allows simple range types because they now have a valid default value
|
||||
if constructed.requiresInit and constructed.skipTypes({tyGenericInst}).kind != tyRange:
|
||||
# TODO: sorts out `nimPreviewRangeDefault` with `ranges` in the future
|
||||
if isDefault:
|
||||
# TODO: be lenient with views and notnil types for now
|
||||
if isDefault and c.config.features * {views, notnil} != {}:
|
||||
localError(c.config, n.info, "The '$1' type doesn't have a valid default value" % typeToString(constructed))
|
||||
else:
|
||||
message(c.config, n.info, warnUnsafeDefault, typeToString(constructed))
|
||||
@@ -676,7 +678,9 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
||||
let seqType = result[1].typ.skipTypes({tyPtr, tyRef, # in case we had auto-dereferencing
|
||||
tyVar, tyGenericInst, tyOwned, tySink,
|
||||
tyAlias, tyUserTypeClassInst})
|
||||
if seqType.kind == tySequence and seqType.base.requiresInit:
|
||||
if seqType.kind == tySequence and seqType.base.requiresInit and
|
||||
seqType.base.skipTypes({tyGenericInst}).kind != tyRange:
|
||||
# allows simple range types because they now have a valid default value
|
||||
message(c.config, n.info, warnUnsafeSetLen, typeToString(seqType.base))
|
||||
of mDefault:
|
||||
result = checkDefault(c, n, true)
|
||||
|
||||
Reference in New Issue
Block a user