fixes #4124
This commit is contained in:
parent
b48e178969
commit
c870e831c8
2 changed files with 33 additions and 3 deletions
|
|
@ -778,11 +778,16 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
|
||||||
var s = a.sons[0].sym
|
var s = a.sons[0].sym
|
||||||
# compute the type's size and check for illegal recursions:
|
# compute the type's size and check for illegal recursions:
|
||||||
if a.sons[1].kind == nkEmpty:
|
if a.sons[1].kind == nkEmpty:
|
||||||
if a.sons[2].kind in {nkSym, nkIdent, nkAccQuoted}:
|
var x = a[2]
|
||||||
|
while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0:
|
||||||
|
x = x.lastSon
|
||||||
|
if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty}:
|
||||||
# type aliases are hard:
|
# type aliases are hard:
|
||||||
#MessageOut('for type ' + typeToString(s.typ));
|
#MessageOut('for type ' + typeToString(s.typ));
|
||||||
var t = semTypeNode(c, a.sons[2], nil)
|
var t = semTypeNode(c, x, nil)
|
||||||
if t.kind in {tyObject, tyEnum}:
|
assert t != nil
|
||||||
|
if t.kind in {tyObject, tyEnum, tyDistinct}:
|
||||||
|
assert s.typ != nil
|
||||||
assignType(s.typ, t)
|
assignType(s.typ, t)
|
||||||
s.typ.id = t.id # same id
|
s.typ.id = t.id # same id
|
||||||
checkConstructedType(s.info, s.typ)
|
checkConstructedType(s.info, s.typ)
|
||||||
|
|
|
||||||
25
tests/types/typeof_produces_alias.nim
Normal file
25
tests/types/typeof_produces_alias.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
# bug #4124
|
||||||
|
|
||||||
|
import sequtils
|
||||||
|
|
||||||
|
type
|
||||||
|
Foo = distinct string
|
||||||
|
|
||||||
|
var
|
||||||
|
foo: Foo
|
||||||
|
|
||||||
|
type
|
||||||
|
Alias = (type(foo))
|
||||||
|
var
|
||||||
|
a: Alias
|
||||||
|
|
||||||
|
a = foo
|
||||||
|
|
||||||
|
when true:
|
||||||
|
var xs = @[1,2,3]
|
||||||
|
|
||||||
|
proc asFoo(i: string): Foo =
|
||||||
|
Foo(i)
|
||||||
|
|
||||||
|
var xx = xs.mapIt(asFoo($(it + 5)))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue