Skip to content

Commit

Permalink
fixes #22673; Cannot prove that result is initialized for a placehold… (
Browse files Browse the repository at this point in the history
#22915)

…er base method returning a lent


fixes #22673
  • Loading branch information
ringabout authored Nov 6, 2023
1 parent b79b391 commit 2e070df
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/cgmeth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ proc sameMethodBucket(a, b: PSym; multiMethods: bool): MethodResult =
return No
if result == Yes:
# check for return type:
if not sameTypeOrNil(a.typ[0], b.typ[0]):
# ignore flags of return types; # bug #22673
if not sameTypeOrNil(a.typ[0], b.typ[0], {IgnoreFlags}):
if b.typ[0] != nil and b.typ[0].kind == tyUntyped:
# infer 'auto' from the base to make it consistent:
b.typ[0] = a.typ[0]
Expand Down
2 changes: 1 addition & 1 deletion compiler/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ type
ExactGcSafety
AllowCommonBase
PickyCAliases # be picky about the distinction between 'cint' and 'int32'
IgnoreFlags # used for borrowed functions; ignores the tfVarIsPtr flag
IgnoreFlags # used for borrowed functions and methods; ignores the tfVarIsPtr flag

TTypeCmpFlags* = set[TTypeCmpFlag]

Expand Down
21 changes: 21 additions & 0 deletions tests/method/t22673.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
discard """
matrix: "--warningAsError:UseBase"
"""

# bug #22673
type RefEntry = ref object of RootObj

type RefFile = ref object of RefEntry
filename*: string
data*: string

type RefDir = ref object of RefEntry
dirname*: string
files*: seq[RefFile]

method name*(e: RefEntry): lent string {.base.} =
raiseAssert "Don't call the base method"

method name*(e: RefFile): lent string = e.filename

method name*(e: RefDir): lent string = e.dirname

0 comments on commit 2e070df

Please sign in to comment.