mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 11:12:37 +00:00
Merge branch 'devel' into pr_remove_macros
This commit is contained in:
@@ -689,8 +689,7 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P
|
||||
result = nil
|
||||
of tyRange:
|
||||
if c.graph.config.isDefined("nimPreviewRangeDefault"):
|
||||
result = newIntNode(nkIntLit, firstOrd(c.config, aTypSkip))
|
||||
result.typ = aTyp
|
||||
result = firstRange(c.config, aTypSkip)
|
||||
else:
|
||||
result = nil
|
||||
else:
|
||||
|
||||
@@ -475,6 +475,13 @@ proc semAnonTuple(c: PContext, n: PNode, prev: PType): PType =
|
||||
let t = semTypeNode(c, it, nil)
|
||||
addSonSkipIntLitChecked(c, result, t, it, c.idgen)
|
||||
|
||||
proc firstRange(config: ConfigRef, t: PType): PNode =
|
||||
if t.skipModifier().kind in tyFloat..tyFloat64:
|
||||
result = newFloatNode(nkFloatLit, firstFloat(t))
|
||||
else:
|
||||
result = newIntNode(nkIntLit, firstOrd(config, t))
|
||||
result.typ = t
|
||||
|
||||
proc semTuple(c: PContext, n: PNode, prev: PType): PType =
|
||||
var typ: PType
|
||||
result = newOrPrevType(tyTuple, prev, c)
|
||||
@@ -491,8 +498,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
|
||||
elif a[^2].kind != nkEmpty:
|
||||
typ = semTypeNode(c, a[^2], nil)
|
||||
if c.graph.config.isDefined("nimPreviewRangeDefault") and typ.skipTypes(abstractInst).kind == tyRange:
|
||||
a[^1] = newIntNode(nkIntLit, firstOrd(c.config, typ))
|
||||
a[^1].typ = typ
|
||||
a[^1] = firstRange(c.config, typ)
|
||||
hasDefaultField = true
|
||||
else:
|
||||
localError(c.config, a.info, errTypeExpected)
|
||||
@@ -846,8 +852,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
|
||||
else:
|
||||
typ = semTypeNode(c, n[^2], nil)
|
||||
if c.graph.config.isDefined("nimPreviewRangeDefault") and typ.skipTypes(abstractInst).kind == tyRange:
|
||||
n[^1] = newIntNode(nkIntLit, firstOrd(c.config, typ))
|
||||
n[^1].typ = typ
|
||||
n[^1] = firstRange(c.config, typ)
|
||||
hasDefaultField = true
|
||||
propagateToOwner(rectype, typ)
|
||||
var fieldOwner = if c.inGenericContext > 0: c.getCurrOwner
|
||||
|
||||
@@ -744,6 +744,10 @@ template main {.dirty.} =
|
||||
var b = default ArrayObj2
|
||||
doAssert b.list[North] == 1
|
||||
|
||||
block:
|
||||
type limited_float = range[1.2..20.0]
|
||||
doAssert default(limited_float) == 1.2
|
||||
|
||||
|
||||
block:
|
||||
type
|
||||
@@ -759,5 +763,13 @@ template main {.dirty.} =
|
||||
|
||||
foo()
|
||||
|
||||
block:
|
||||
type
|
||||
Object = object
|
||||
id: range[1.2..29.3]
|
||||
|
||||
var s = default(Object)
|
||||
doAssert s.id == 1.2
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user