Skip to content

Commit

Permalink
* fixed nimsuggest crash with 'Something = concept' put (erroneously)…
Browse files Browse the repository at this point in the history
… outside of a 'type' block (nim-lang#23331)
  • Loading branch information
nickysn authored Feb 24, 2024
1 parent 6ce6cd4 commit 37ed8c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ proc parseTypeDesc(p: var Parser, fullExpr = false): PNode =
result = newNodeP(nkObjectTy, p)
getTok(p)
of tkConcept:
result = nil
result = p.emptyNode
parMessage(p, "the 'concept' keyword is only valid in 'type' sections")
of tkVar: result = parseTypeDescKAux(p, nkVarTy, pmTypeDesc)
of tkOut: result = parseTypeDescKAux(p, nkOutTy, pmTypeDesc)
Expand Down
12 changes: 12 additions & 0 deletions nimsuggest/tests/tconcept1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SomeNumber = concept

#[!]#
discard """
$nimsuggest --tester $file
>chk $1
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tconcept1.nim [Processing]";;0
chk;;skUnknown;;;;Error;;$file;;1;;13;;"the \'concept\' keyword is only valid in \'type\' sections";;0
chk;;skUnknown;;;;Error;;$file;;1;;13;;"invalid indentation";;0
chk;;skUnknown;;;;Error;;$file;;1;;13;;"expression expected, but found \'keyword concept\'";;0
chk;;skUnknown;;;;Error;;$file;;1;;0;;"\'SomeNumber\' cannot be assigned to";;0
"""
15 changes: 15 additions & 0 deletions nimsuggest/tests/tconcept2.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SomeNumber = concept a, type T
a.int is int
int.to(T) is type(a)

#[!]#
discard """
$nimsuggest --tester $file
>chk $1
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tconcept2.nim [Processing]";;0
chk;;skUnknown;;;;Error;;$file;;1;;2;;"invalid indentation";;0
chk;;skUnknown;;;;Error;;$file;;1;;15;;"the \'concept\' keyword is only valid in \'type\' sections";;0
chk;;skUnknown;;;;Error;;$file;;1;;15;;"invalid indentation";;0
chk;;skUnknown;;;;Error;;$file;;1;;15;;"expression expected, but found \'keyword concept\'";;0
chk;;skUnknown;;;;Error;;$file;;1;;2;;"\'SomeNumber\' cannot be assigned to";;0
"""

0 comments on commit 37ed8c8

Please sign in to comment.