diff options
author | Nikolay Nikolov <nickysn@gmail.com> | 2024-02-24 08:55:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-24 07:55:23 +0100 |
commit | 37ed8c84801a850b91b86f777ae2a4a2e022cd47 (patch) | |
tree | a69dc6e9f8a65b1993b979f8ef69fb191907e6eb | |
parent | 6ce6cd4bb8e59c9f5a2c4588d2d34b9306e03d63 (diff) | |
download | Nim-37ed8c84801a850b91b86f777ae2a4a2e022cd47.tar.gz |
* fixed nimsuggest crash with 'Something = concept' put (erroneously) outside of a 'type' block (#23331)
-rw-r--r-- | compiler/parser.nim | 2 | ||||
-rw-r--r-- | nimsuggest/tests/tconcept1.nim | 12 | ||||
-rw-r--r-- | nimsuggest/tests/tconcept2.nim | 15 |
3 files changed, 28 insertions, 1 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index 9390c7d1b..b261e584f 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -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) diff --git a/nimsuggest/tests/tconcept1.nim b/nimsuggest/tests/tconcept1.nim new file mode 100644 index 000000000..d81cd8120 --- /dev/null +++ b/nimsuggest/tests/tconcept1.nim @@ -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 +""" diff --git a/nimsuggest/tests/tconcept2.nim b/nimsuggest/tests/tconcept2.nim new file mode 100644 index 000000000..7f7d147f5 --- /dev/null +++ b/nimsuggest/tests/tconcept2.nim @@ -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 +""" |