mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 23:41:29 +00:00
* 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:
@@ -1474,7 +1474,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
|
||||
if c.config.cmd == cmdIdeTools: suggestExpr(c, n)
|
||||
case n.kind
|
||||
of nkEmpty: discard
|
||||
of nkEmpty: result = n.typ
|
||||
of nkTypeOfExpr:
|
||||
# for ``type(countup(1,3))``, see ``tests/ttoseq``.
|
||||
checkSonsLen(n, 1, c.config)
|
||||
|
||||
@@ -4,6 +4,7 @@ output: '''
|
||||
Hallo Welt
|
||||
Hallo Welt
|
||||
1
|
||||
()
|
||||
'''
|
||||
"""
|
||||
|
||||
@@ -34,3 +35,17 @@ macro t(): untyped =
|
||||
t()
|
||||
|
||||
echo tp()
|
||||
|
||||
|
||||
# https://github.com/nim-lang/Nim/issues/9866
|
||||
type
|
||||
# Foo = int # works
|
||||
Foo = object # fails
|
||||
|
||||
macro dispatchGen(): untyped =
|
||||
var shOpt: Foo
|
||||
result = quote do:
|
||||
let baz = `shOpt`
|
||||
echo `shOpt`
|
||||
|
||||
dispatchGen()
|
||||
|
||||
@@ -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]()
|
||||
|
||||
Reference in New Issue
Block a user