diff options
author | Jake Leahy <jake@leahy.dev> | 2023-07-06 16:18:47 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 08:18:47 +0200 |
commit | 7616e6ee2b48a3c3504684f3324a42e95bd73790 (patch) | |
tree | a275aa09625c499509e3f59c4211aedbfd849f32 | |
parent | 145e002c74c4393b9ac71d5a8cfe066fbf38a048 (diff) | |
download | Nim-7616e6ee2b48a3c3504684f3324a42e95bd73790.tar.gz |
Fix concepts with doc comments (#22228)
* Add testcase This tries to use a concept with a doc comment which currently leads to a segfault * Ignore nil nodes which happen when there are doc comments in new style concept This was done instead of semming the comments since `semConceptDecl` says it only supports lists of actual statements * Go with alternative fix: Sem comments but ignore them Since `nil` could mean anything it is best to not silently ignore it (In case another nil problem happens in future Also fix test case so it isn't an infinite loop
-rw-r--r-- | compiler/concepts.nim | 4 | ||||
-rw-r--r-- | tests/concepts/tconcepts.nim | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/concepts.nim b/compiler/concepts.nim index 6a383a937..c980cf7ef 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -62,7 +62,7 @@ proc semConceptDecl(c: PContext; n: PNode): PNode = result[i] = n[i] result[^1] = semConceptDecl(c, n[^1]) of nkCommentStmt: - discard + result = n else: localError(c.config, n.info, "unexpected construct in the new-styled concept: " & renderTree(n)) result = n @@ -306,6 +306,8 @@ proc conceptMatchNode(c: PContext; n: PNode; m: var MatchCon): bool = result = matchSyms(c, n, {skMethod}, m) of nkIteratorDef: result = matchSyms(c, n, {skIterator}, m) + of nkCommentStmt: + result = true else: # error was reported earlier. result = false diff --git a/tests/concepts/tconcepts.nim b/tests/concepts/tconcepts.nim index acdff6f24..ea3ddc401 100644 --- a/tests/concepts/tconcepts.nim +++ b/tests/concepts/tconcepts.nim @@ -31,6 +31,7 @@ e 20 10 5 +9 ''' """ @@ -438,3 +439,13 @@ import mvarconcept block tvar: # bug #2346, bug #2404 echo randomInt(5) + +block tcomment: + type + Foo = concept + ## Some comment + proc bar(x: Self) + + proc bar(x: int) = echo x + proc foo(x: Foo) = x.bar + foo(9) |