mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-12 01:55:34 +00:00
fixes #25784; Object field initialized with an object constructor
This commit is contained in:
@@ -486,6 +486,11 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
|
||||
# we have to watch out, there are also 'owned proc' types that can be used
|
||||
# multiple times as long as they don't have closures.
|
||||
result.typ.incl tfHasOwned
|
||||
if t.kind == tyForward and n.len == 1 and efDetermineType in flags:
|
||||
# a forward object type does not error during determine-type analysis;
|
||||
# it now stays unresolved long enough for the existing delayed field-default pass to resolve it after the type section finishes.
|
||||
result.typ = t
|
||||
return result
|
||||
if t.kind != tyObject:
|
||||
return localErrorNode(c, result, if t.kind != tyGenericBody:
|
||||
"object constructor needs an object type".dup(addTypeNodeDeclaredLoc(c.config, t))
|
||||
|
||||
@@ -13,3 +13,25 @@ type
|
||||
pendingTasks*: range[0'i32 .. high(int32)]
|
||||
head: T
|
||||
tail: T
|
||||
|
||||
block:
|
||||
type
|
||||
Foo = object
|
||||
x = Bar()
|
||||
|
||||
Bar = object
|
||||
x: int
|
||||
|
||||
var f = Foo()
|
||||
doassert f.x.x == 0
|
||||
|
||||
block:
|
||||
type
|
||||
Bar = object
|
||||
x: int
|
||||
|
||||
Foo = object
|
||||
x = Bar()
|
||||
|
||||
var f = Foo()
|
||||
doassert f.x.x == 0
|
||||
|
||||
Reference in New Issue
Block a user