Skip to content

Commit 55649a2

Browse files
committed
supports distinct types
1 parent 89f8874 commit 55649a2

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

compiler/icnif/nifdecodertypes.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ proc fromNifType(c: var DecodeContext; n: var Cursor): PType =
121121
result = nil
122122
else:
123123
let k = readTypeKind(n, tag)
124+
assert k != tyNone
124125
if k in SysTypeKinds:
125126
result = getSysType(c, k)
126127
else:

compiler/icnif/nifencoder.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ proc toNifTypeSection(c: var EncodeContext; n: PNode) =
114114

115115
let last = n[2]
116116
if name.kind == nkSym:
117-
if last.kind == nkEmpty and name.sym.typ != nil:
118-
toNif c, name.sym.typ, true
119-
elif name.sym.typ != nil and name.sym.typ.kind in {tyEnum, tyObject} and name.sym.typ.n != nil:
117+
if name.sym.typ != nil:
120118
toNif c, name.sym.typ, true
121119
else:
122120
toNif c, last

compiler/icnif/nifencodertypes.nim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,20 @@ proc toNif(c: var EncodeContext; t: PType; isTypeSection = false) =
9090
#toNif c, t.last
9191
c.typeHead t:
9292
for _, son in t.ikids: toNif c, son
93-
of tyDistinct, tyEnum:
93+
of tyEnum:
9494
if isTypeSection:
9595
c.typeHead t:
9696
for son in t.n:
9797
symdefToNif c, son
9898
else:
9999
symToNif c, t.sym
100+
of tyDistinct:
101+
if isTypeSection:
102+
c.typeHead t:
103+
for son in t.kids:
104+
toNif c, son
105+
else:
106+
symToNif c, t.sym
100107
of tyPtr:
101108
if isNominalRef(t):
102109
symToNif c, t.sym

tests/icnif/testcode/modtesttypesections.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ type
33
TestEnum = enum
44
X
55
Y
6+
TestDistinct = distinct int
67

78
var x: TestInt
89
var testEnum: TestEnum
910
var testEnum1 = X
11+
var testDistinct: TestDistinct

0 commit comments

Comments
 (0)