not nil types are illegal to construct through default(T)

This commit is contained in:
Zahary Karadjov 2020-03-29 02:34:50 +02:00 • committed by Andreas Rumpf
commit f3be5a716f
2 changed files with 16 additions and 0 deletions

View file

@ -2270,6 +2270,8 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
let typ = result[1].typ.base
if typ.kind == tyObject:
checkDefaultConstruction(c, typ, n.info)
elif typ.kind in {tyRef, tyPtr} and tfNotNil in typ.flags:
localError(c.config, n.info, "not nil types don't have a default value")
else:
result = semDirectOp(c, n, flags)