mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user