Skip to content

Commit 3eeae01

Browse files
authored
fix inner ref object not semchecking in bodies phase (#1182)
fixes #1180 Type decls only get semchecked if either: * semchecking is in the signature phase * semchecking is in any phase except toplevelsyms and the type does not have a symbol yet/is from generics/templates Since inner ref objects already have a symbol and the `block` only semchecks at the bodies phase, we need to run the signature phase again here so that the inner object type is semchecked.
1 parent c7e551c commit 3eeae01

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/nimony/semdecls.nim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ proc semTypeSection(c: var SemContext; n: var Cursor) =
814814
swap c.dest, c.pending
815815

816816
if isRefPtrObj:
817-
if c.phase != SemcheckTopLevelSyms:
817+
if c.phase > SemcheckTopLevelSyms:
818818
var topLevelDest = createTokenBuf(64)
819819
var topLevelRead = beginRead(innerObjDecl)
820820
var phase = SemcheckTopLevelSyms
@@ -824,6 +824,17 @@ proc semTypeSection(c: var SemContext; n: var Cursor) =
824824
swap c.dest, topLevelDest
825825
swap c.phase, phase
826826
innerObjDecl = topLevelDest
827+
if c.phase > SemcheckSignatures:
828+
# need to go through signature phase if not applied yet since decl already has sym
829+
var sigDest = createTokenBuf(64)
830+
var sigRead = beginRead(innerObjDecl)
831+
var phase = SemcheckSignatures
832+
swap c.phase, phase
833+
swap c.dest, sigDest
834+
semTypeSection c, sigRead
835+
swap c.dest, sigDest
836+
swap c.phase, phase
837+
innerObjDecl = sigDest
827838
var decl = beginRead(innerObjDecl)
828839
semTypeSection c, decl
829840

tests/nimony/types/tscopedtype.nif

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(.nif24)
2+
0,1,tests/nimony/types/tscopedtype.nim(stmts ,2
3+
(block . 2,1
4+
(stmts 6,1
5+
(type ~4 :Foo.0.tsca4az8i1 . . . 2
6+
(ref 4 Foo.Obj.0.tsca4az8i1)) 6,1
7+
(type ~4 :Foo.Obj.0.tsca4az8i1 . . . 6
8+
(object 10 RootObj.0.sysvq0asl ~8,1
9+
(fld :id.0.tsca4az8i1 . . 4
10+
(i -1) .))) 4,4
11+
(var :s.0 . . 4,~3
12+
(ref 4 Foo.Obj.0.tsca4az8i1) 7
13+
(newobj ~3,~3
14+
(ref 4 Foo.Obj.0.tsca4az8i1) 3
15+
(kv ~2 id.0.tsca4az8i1 2 +12))) 2,116,lib/std/syncio.nim
16+
(stmts 2,1
17+
(stmts
18+
(cmd write.2.syn1lfpjv 6 stdout.0.syn1lfpjv 8,9,tests/nimony/types/tscopedtype.nim
19+
(ddot ~1 s.0 id.0.tsca4az8i1 +0))) ,2
20+
(cmd write.5.syn1lfpjv 6 stdout.0.syn1lfpjv 14 '\0A')))))

tests/nimony/types/tscopedtype.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import std/syncio
2+
3+
block:
4+
type
5+
Foo = ref object of RootObj
6+
id: int
7+
8+
var s = Foo(id: 12)
9+
echo s.id
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12

0 commit comments

Comments
 (0)