fix #10339 by returning type attached to nkEmpty (#10370)

* fix #10339 by checking for nkObjConstr

* revert check for nkObjConstr, return type from nkEmpty node

The correct type needed in `semObjConstr` to fix #10339 is indeed
available, but attached to an `nkEmpty` node. These were previously
discarded in `semTypeNode`, which is used to extract the type for the
object.

* simplify return of PType from  `nkEmpty`

* also fixes #9866, add test case
This commit is contained in:
Vindaar 2019-01-23 11:17:32 +01:00 • committed by Andreas Rumpf
commit d9ee377517
3 changed files with 33 additions and 1 deletions

View file

@ -137,3 +137,20 @@ block:
type
Coord[N: static[int]] = tuple[col, row: range[0'i8 .. (N.int8-1)]]
Point[N: static[int]] = range[0'i16 .. N.int16 * N.int16 - 1]
# https://github.com/nim-lang/Nim/issues/10339
block:
type
MicroKernel = object
a: float
b: int
macro extractA(ukernel: static MicroKernel): untyped =
result = newLit ukernel.a
proc tFunc[ukernel: static MicroKernel]() =
const x = ukernel.extractA
doAssert x == 5.5
const uk = MicroKernel(a: 5.5, b: 1)
tFunc[uk]()