Skip to content

Commit 9ae31a1

Browse files
authored
refactorings and import handling (#1157)
1 parent f0b21b4 commit 9ae31a1

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

src/nimony/derefs.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ proc tr(c: var Context; n: var Cursor; e: Expects) =
715715
case n.kind
716716
of Symbol:
717717
let localInfo = c.typeCache.getLocalInfo(n.symId)
718-
if localInfo.crossedProc:
718+
if localInfo.crossedProc and localInfo.kind in {VarY, LetY, ParamY, ResultY}:
719719
let info = n.info
720720
c.dest.buildTree ErrT, info:
721721
c.dest.addSubtree n

src/nimony/semimport.nim

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ proc doImports(c: var SemContext; files: seq[ImportedFilename]; mode: ImportFilt
9797
for f in files:
9898
importSingleFileConsiderExports c, f, origin, mode, info
9999

100-
proc semImport(c: var SemContext; it: var Item) =
101-
let info = it.n.info
102-
var x = it.n
103-
skip it.n
104-
inc x # skip the `import`
105-
100+
template maybeCyclic(c: var SemContext; x: var Cursor) =
106101
if x.kind == ParLe and x.exprKind == PragmaxX:
107102
inc x
108103
var y = x
@@ -113,6 +108,13 @@ proc semImport(c: var SemContext; it: var Item) =
113108
cyclicImport(c, x)
114109
return
115110

111+
proc semImport(c: var SemContext; it: var Item) =
112+
let info = it.n.info
113+
var x = it.n
114+
skip it.n
115+
inc x # skip the `import`
116+
maybeCyclic(c, x)
117+
116118
var files: seq[ImportedFilename] = @[]
117119
var hasError = false
118120
while x.kind != ParRi:
@@ -130,15 +132,7 @@ proc semImportExcept(c: var SemContext; it: var Item) =
130132
skip it.n
131133
inc x # skip the `importexcept`
132134

133-
if x.kind == ParLe and x.exprKind == PragmaxX:
134-
inc x
135-
var y = x
136-
skip y
137-
if y.substructureKind == PragmasU:
138-
inc y
139-
if y.kind == Ident and pool.strings[y.litId] == "cyclic":
140-
cyclicImport(c, x)
141-
return
135+
maybeCyclic(c, x)
142136

143137
var files: seq[ImportedFilename] = @[]
144138
var hasError = false
@@ -159,15 +153,7 @@ proc semFromImport(c: var SemContext; it: var Item) =
159153
skip it.n
160154
inc x # skip the `from`
161155

162-
if x.kind == ParLe and x.exprKind == PragmaxX:
163-
inc x
164-
var y = x
165-
skip y
166-
if y.substructureKind == PragmasU:
167-
inc y
168-
if y.kind == Ident and pool.strings[y.litId] == "cyclic":
169-
cyclicImport(c, x)
170-
return
156+
maybeCyclic(c, x)
171157

172158
var files: seq[ImportedFilename] = @[]
173159
var hasError = false

src/nimony/typenav.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ proc getLocalInfo*(c: var TypeCache; s: SymId): LocalInfo =
9898
if it.kind == compareTo:
9999
crossedProc = true
100100
if res.kind != NoSym:
101-
res.crossedProc = crossedProc and res.kind in {VarY, LetY, ParamY, ResultY}
101+
res.crossedProc = crossedProc
102102
return res
103103
it = it.parent
104104
compareTo = ProcScope

0 commit comments

Comments
 (0)