From 2e070dfc76a1badfaad08d62b0f3f02f6ba2bc02 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 7 Nov 2023 02:36:26 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20#22673;=20Cannot=20prove=20that=20resul?= =?UTF-8?q?t=20is=20initialized=20for=20a=20placehold=E2=80=A6=20(#22915)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …er base method returning a lent fixes #22673 --- compiler/cgmeth.nim | 3 ++- compiler/types.nim | 2 +- tests/method/t22673.nim | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/method/t22673.nim diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 8ad6bf3f4b92d..5821988bb6cfe 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -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] diff --git a/compiler/types.nim b/compiler/types.nim index 46433a2306ddd..4bc78cbb80f68 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -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] diff --git a/tests/method/t22673.nim b/tests/method/t22673.nim new file mode 100644 index 0000000000000..1689e9d42650e --- /dev/null +++ b/tests/method/t22673.nim @@ -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 \ No newline at end of file