Skip to content

Commit

Permalink
fix nimsuggest crash with arrow type sugar (#24185)
Browse files Browse the repository at this point in the history
fixes #24179 

The original fix made it so calls to `skError`/`skUnknown` (in this case
`->`, for some reason `sugar` couldn't be imported) returned an error
node, however this breaks tsug_accquote for some reason I don't
understand (it even parses as `tsug_accquote.discard`) so I've just
added a guard based on the stacktrace.
  • Loading branch information
metagn authored Sep 27, 2024
1 parent 1bd5a4a commit fd379c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ proc analyseIfAddressTaken(c: PContext, n: PNode, isOutParam: bool): PNode =

proc analyseIfAddressTakenInCall(c: PContext, n: PNode, isConverter = false) =
checkMinSonsLen(n, 1, c.config)
if n[0].typ == nil:
# n[0] might be erroring node in nimsuggest
return
const
FakeVarParams = {mNew, mNewFinalize, mInc, ast.mDec, mIncl, mExcl,
mSetLengthStr, mSetLengthSeq, mAppendStrCh, mAppendStrStr, mSwap,
Expand Down
20 changes: 20 additions & 0 deletions nimsuggest/tests/tarrowcrash.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# issue #24179

import sugar

type
Parser[T] = object

proc eatWhile[T](p: Parser[T], predicate: T -> bool): seq[T] =
return @[]

proc skipWs(p: Parser[char]) =
discard p.eatWhile((c: char) => c == 'a')
#[!]#

discard """
$nimsuggest --tester $file
>chk $1
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tarrowcrash.nim [Processing]";;0
chk;;skUnknown;;;;Hint;;$file;;11;;5;;"\'skipWs\' is declared but not used [XDeclaredButNotUsed]";;0
"""
2 changes: 1 addition & 1 deletion tests/errmsgs/tundeclared_routine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tundeclared_routine.nim(29, 28) Error: invalid pragma: myPragma
tundeclared_routine.nim(36, 13) Error: undeclared field: 'bar3' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(33, 8)]
found tundeclared_routine.bar3() [iterator declared in tundeclared_routine.nim(35, 12)]
tundeclared_routine.nim(41, 13) Error: undeclared field: 'bar4' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(39, 8)]
tundeclared_routine.nim(44, 15) Error: attempting to call routine: 'bad5'
tundeclared_routine.nim(44, 11) Error: undeclared identifier: 'bad5'
'''
"""

Expand Down

0 comments on commit fd379c2

Please sign in to comment.