Replace tfHasRequiresInit with a more accurate mechanism
The new mechanism can deal with more complex scenarios such as not nil field appearing in a non-default case object branch or a field within a generic object that may depend on a when branch. The commit also plugs another hole: the user is no longer able to create illegal default values through seq.setLen(N).
This commit is contained in:
parent
d374c6373b
commit
ce9a4ed124
11 changed files with 179 additions and 43 deletions
|
|
@ -614,8 +614,10 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
|||
else: v.typ = tup
|
||||
b[j] = newSymNode(v)
|
||||
if def.kind == nkEmpty:
|
||||
if v.typ.kind == tyObject:
|
||||
checkDefaultConstruction(c, v.typ, v.info)
|
||||
let actualType = v.typ.skipTypes({tyGenericInst, tyAlias,
|
||||
tyUserTypeClassInst})
|
||||
if actualType.kind == tyObject and actualType.requiresInit:
|
||||
defaultConstructionError(c, v.typ, v.info)
|
||||
else:
|
||||
checkNilable(c, v)
|
||||
if sfCompileTime in v.flags:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue