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
This commit is contained in:
Jake Leahy
2023-07-06 16:18:47 +10:00
committed by GitHub
parent 145e002c74
commit 7616e6ee2b
2 changed files with 14 additions and 1 deletions

View File

@@ -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

View File

@@ -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)