diff --git a/compiler/sem.nim b/compiler/sem.nim index 3392db7a9d..c70cf412b5 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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 diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index e5799c5c1f..667abb9aaf 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -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)